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 a[500005], n;
int range(int s, int e){
if(s <= 0){
return a[e] + (a[n] - a[s + n - 1]);
}
return a[e] - a[s - 1];
}
int cur1[500005], cur2[500005];
deque<int> dq, num;
int main(){
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
for (int i = 1; i <= n; i++) {
cur1[i - 1] = range(i - (n - 1)/2, i);
}
for (int i = 0; i < n + (n - 1)/2; i++) {
if(!num.empty() && num.front() == i - (n + 1) / 2){
num.pop_front();
dq.pop_front();
}
while (!dq.empty() && dq.back() > cur1[i % n]) {
num.pop_back();
dq.pop_back();
}
dq.push_back(cur1[i % n]);
num.push_back(i);
if(i - (n - 1)/2 >= 0){
cur2[i - (n - 1)/2] = dq.front();
}
}
cout << *max_element(cur2,cur2+n) << "\n";
}
# | 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... |