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;
int n,a[500005],pre[500005],sum,r,l,ans,ttl;
priority_queue <pair<int,int> > mx;
bool chk(int x,int y,int a1){
if (x > y){
if (a1 >= x || a1 <= y)
return false;
return true;
}
else
{
if (x <= a1 && a1 <= y)
return false;
return true;
}
}
int main(){
ios::sync_with_stdio(false);
cin >> n; ans=2e9;
for (int i=0;i<n;i++){
cin >> a[i];
ttl+=a[i];
}
r=n/2-1;
for (int i=0;i<n/2;i++){
sum+=a[i];
}
for (int i=0;i<n;i++){
pre[i]=sum;
sum-=a[i];
r++; r%=n;
sum+=a[r];
}
l=n/2; r=n-1;
for (int i=l;i<=r;i++){
mx.push(make_pair(pre[i],i));
}
for (int i=0;i<n;i++){
while (!mx.empty() && chk(l,r,mx.top().second)){
mx.pop();
}
ans=min(ans,mx.top().first);
l++; r++; l%=n; r%=n;
mx.push(make_pair(pre[r],r));
}
cout << ttl-ans << "\n";
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... |