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[1000007],pre[1000007],ans=0;
deque <int> cur;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
a[n+i]=a[i];
}
int sz=(n/2)+(n%2);
for(int i=1;i<=sz;i++){
pre[1]+=a[i];
}
for(int i=2;i<=n;i++){
pre[i]=pre[i-1]+a[i+sz-1]-a[i-1];
}
for(int i=1;i<=n;i++) pre[n+i]=pre[i];
for(int i=1;i<=2*n;i++){
while(!cur.empty() && pre[cur.back()]>=pre[i]) cur.pop_back();
cur.push_back(i);
if(i-cur.front()==sz) cur.pop_front();
if(i>=sz) ans=max(ans,pre[cur.front()]);
}
cout<<ans;
}
# | 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... |