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 main() {
ios::sync_with_stdio(0), cin.tie(0);
int N; cin >> N;
int a[N] = {}, b[2*N], pref = 0;
int x = (N + 1) / 2;
for(int &i : a) cin >> i;
for(int i = 0; i - x < N; i++) {
if(i && i < N) a[i] += a[i-1];
pref = a[i % N];
if(i >= N) pref += a[N - 1];
if(i >= x)
b[i-x+N] = b[i-x] = pref - a[i-x];
}
int *l = a, *r = a, res = 0;
for(int i = 0; i < 2*N; i++) {
while(l != r && b[*(r-1)] >= b[i]) --r;
(*r++) = i;
while(*l <= i-x) ++l;
if(i >= x-1) res = max(res, b[*l]);
}
cout << res;
}
# | 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... |