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>
using namespace std;
#define ll long long
#define ar array
const int mxN=5e5;
int n, a[2*mxN], p[2*mxN+1], val[2*mxN+1];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i=0; i<n; ++i) {
cin >> a[i];
a[i+n]=a[i];
}
for (int i=0; i<2*n; ++i)
p[i+1]=p[i]+a[i];
for (int i=1; i+n/2<=2*n; ++i)
val[i]=p[i+n/2]-p[i];
int ans=0;
/*for (int i=0; i<n; ++i) {
int mx=0;
for (int j=1; j<=(n+1)/2; ++j)
mx=max(mx, val[i+j]);
ans=max(ans, p[n]-mx);
}*/
deque<int> dq;
for (int i=1; i<=n-1+(n+1)/2; ++i) {
while(dq.size()&&val[i]>=val[dq.back()])
dq.pop_back();
dq.push_back(i);
if (i-dq[0]>=(n+1)/2)
dq.pop_front();
assert(dq.size());
if (i>=(n+1)/2)
ans=max(ans, p[n]-val[dq[0]]);
}
cout << ans;
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... |