This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define DIM 1000010
using namespace std;
int v[DIM],sp[DIM];
deque <pair<int,int> > d;
int n,i;
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n;
for (i=1;i<=n;i++)
cin>>v[i];
int lg = (n+1) / 2;
for (i=n+1;i<=2*n;i++)
v[i] = v[i-n];
for (i=1;i<=2*n;i++)
sp[i] = sp[i-1] + v[i];
for (i=lg;i<2*lg;i++){
while (!d.empty() && sp[i] - sp[i-lg] <= d.back().first)
d.pop_back();
d.push_back(make_pair(sp[i] - sp[i-lg],i));
}
int sol = d.front().first;
for (i=2*lg;i<=2*n;i++){
while (!d.empty() && sp[i] - sp[i-lg] <= d.back().first)
d.pop_back();
d.push_back(make_pair(sp[i] - sp[i-lg],i));
while (d.front().second <= i-lg)
d.pop_front();
sol = max (sol,d.front().first);
}
cout<<sol;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |