Đăng nhập để hỏi chi tiết
Input: bridge.inp
100
6
50
30
10
10
40
50
Output: bridge.out
5
Giải thích:
Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
\begin{array}{c} \color{#F5FAFF}{F} \color{#9EC1E9}{u} \color{#7DA6D9}{r} \color{#5C8BCD}{i} \color{#7A9CCF}{n} \color{#8BB0D9}{a} \color{#8BB0D9}{F} \color{#7A9CCF}{o} \color{#5C8BCD}{r} \color{#7DA6D9}{c} \color{#9EC1E9}{a} \color{#F5FAFF}{l} \color{#9EC1E9}{o} \color{#FFFFFF}{s} \end{array}
/**
* author: furina focalors
* from : A3K59 DHV
* created: 20.09.2025
**/
#include<bits/stdc++.h>
#define hutao long long
using namespace std;
hutao a[1000005];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
hutao w,n;
cin>>w>>n;
for(hutao i=1;i<=n;i++)
{
cin>>a[i];
}
hutao sum=0;
hutao tong=0;
queue<hutao> q;
for(hutao i=1;i<=n;i++)
{
q.push(a[i]);
sum+=a[i];
if(q.size()>4)
{
sum-=q.front();
q.pop();
}
if(sum>w)
{
break;
}
tong=i;
}
cout<<tong;
}
Hãy giúp mọi người biết câu trả lời này thế nào?
#include <bits/stdc++.h>
using namespace std;
//typedef long long ll;
#define int long long
int n, w;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> w >> n;
deque<int> q;
int sum = 0;
for (int i = 1; i <= n; ++i) {
int c;
cin >> c;
q.push_back(c);
sum += c;
if (q.size() > 4) {
sum -= q.front();
q.pop_front();
}
if (sum > w) {
return cout << i - 1, 0;
}
}
cout << n;
return 0;
}
Hãy giúp mọi người biết câu trả lời này thế nào?
Bảng tin
138
828
74
dùng cách khác đi
1724
10674
2573
đổi đc mỗi ctdl chứ chả nghĩ ra cách !=
138
828
74
=)))