# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
676498 | penguin133 | Hacker (BOI15_hac) | C++17 | 59 ms | 20404 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;
#define int long long
int dp[1000005], B[1000005], P[1000005], S[500005];
deque<int>dq;
main(){
ios::sync_with_stdio(0);cin.tie(0);
int n;cin >> n;
for(int i=1;i<=n;i++)cin >> B[i];
for(int i=n+1;i<=n*2;i++)B[i] = B[i-n];
for(int i=1;i<=2*n;i++)P[i] = P[i-1] + B[i];
int x = n / 2;
for(int i=1;i<=n-x;i++){
while(!dq.empty() && P[dq.back() + x-1] - P[dq.back()-1] < P[i+x-1] - P[i-1])dq.pop_back();
dq.push_back(i);
}
int maxi = 1e9;
for(int i=1;i<=n;i++){
while(!dq.empty() && P[dq.back() + x-1] - P[dq.back()-1] < P[n+i-1] - P[n+i-x-1])dq.pop_back();
if(!dq.empty() && dq.front() == i)dq.pop_front();
dq.push_back(n+i-x);
maxi = min(maxi, P[dq[0] + x - 1] - P[dq[0] - 1]);
}
cout << P[n] - maxi;
}
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... |