# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
31574 | ngkan146 | Hacker (BOI15_hac) | C++98 | 103 ms | 6976 KiB |
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;
int sum = 0;
int a[500005],b[500005];
deque <int> dq;
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]), sum += a[i];
for(int i=0;i<n/2;i++)
b[0] += a[i];
for(int i=1;i<n;i++)
b[i] = b[i-1] - a[i-1] + a[(i+n/2-1+n)%n];
for(int i=1;i<=n/2 + (n%2==1);i++){
if (!dq.size()) dq.push_back(i);
else{
while(dq.size() && b[dq.back()] < b[i]) dq.pop_back();
dq.push_back(i);
}
}
int ans = 0;
for(int i=0;i<n;i++){
if (dq.front() == i) dq.pop_front();
//cout << b[dq.front()] << endl;
ans = max(ans, sum - b[dq.front()]);
while(dq.size() && b[dq.back()] < b[(i+n/2 + (n%2==1)+1)%n]) dq.pop_back();
dq.push_back((i+n/2 + (n%2==1)+1)%n);
}
cout << ans;
}
Compilation message (stderr)
# | 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... |