Submission #1036665

#TimeUsernameProblemLanguageResultExecution timeMemory
1036665NonozeHacker (BOI15_hac)C++17
100 / 100
45 ms6488 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...