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;
void solve() {
int n; cin >> n;int mid=n/2+n%2, x;vector<int> a(n+n, 0);for (int i=0; i<n; i++) {cin >> x;a[i]=(x+a[i-1]);
}
for (int i=n; i<n+n; i++) a[i]=a[n-1]+a[i-n];
deque<int> curr;
for (int i=0; i<mid; i++) {
while (!curr.empty() && a[curr.front()+mid-1]-(curr.front()?a[curr.front()-1]:0)>=a[i+mid-1]-a[i-1]) curr.pop_front();
curr.push_front(i);
}
int ans=0;
for (int i=mid; i<n+mid; i++) {
ans=max(ans, a[curr.back()+mid-1]-a[curr.back()-1]);
while (!curr.empty() && a[curr.front()+mid-1]-a[curr.front()-1]>=a[i+mid-1]-a[i-1]) curr.pop_front();
if (!curr.empty() && curr.back()==i-mid) curr.pop_back();
curr.push_front(i);
}
cout << ans << endl;
return;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
# | 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... |