I used the C++ queue to find the maximum value of the partial sum of the given sequence, but it does not AC.The test case at the original site shows the same output, but half of the atcoder shows WA.
#include<bits/stdc++.h>
#define_GLIBCXX_DEBUG
# define rep(i,n) for (inti=0;i<n;i++)
# define reps(i,n) for (inti=1;i<=n;i++)
#define INF1e9
# define ALL(v) v. begin(), v. end()
using namespace std;
using ll = long long;
int main() {
int n,k;
cin>>n>>k;
lls = 0;
lla;
queue<int>q;
rep(i,k){
cin>>a;
s+=a;
q.push(a);
}
llans=s;
if(n>k){
rep(i,n-k){
cin>>a;
s - = q.front();
q.pop();
s+=a;
q.push(a);
an=max(ans,s);
}
}
cout<<ans;
}
As Metropolis pointed out, the problem seems to be that there is no new line (std::endl).
std::endl has the ability to call std::basic_stream::flush() as well as line breaks.
Otherwise, the output data will not be written to the standard output while being buffered.
Therefore, it depends on the buffer whether the program flushes or not, so depending on luck, sometimes it becomes WA.
© 2024 OneMinuteCode. All rights reserved.