Submission #589683

#TimeUsernameProblemLanguageResultExecution timeMemory
589683penguinhackerHacker (BOI15_hac)C++17
100 / 100
66 ms13640 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array const int mxN=5e5; int n, a[2*mxN], p[2*mxN+1], val[2*mxN+1]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i=0; i<n; ++i) { cin >> a[i]; a[i+n]=a[i]; } for (int i=0; i<2*n; ++i) p[i+1]=p[i]+a[i]; for (int i=1; i+n/2<=2*n; ++i) val[i]=p[i+n/2]-p[i]; int ans=0; /*for (int i=0; i<n; ++i) { int mx=0; for (int j=1; j<=(n+1)/2; ++j) mx=max(mx, val[i+j]); ans=max(ans, p[n]-mx); }*/ deque<int> dq; for (int i=1; i<=n-1+(n+1)/2; ++i) { while(dq.size()&&val[i]>=val[dq.back()]) dq.pop_back(); dq.push_back(i); if (i-dq[0]>=(n+1)/2) dq.pop_front(); assert(dq.size()); if (i>=(n+1)/2) ans=max(ans, p[n]-val[dq[0]]); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...