Submission #535688

#TimeUsernameProblemLanguageResultExecution timeMemory
535688__VariattoHacker (BOI15_hac)C++17
100 / 100
70 ms10188 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define ll long long const int MAX=5e5+10; int n, t[2*MAX], pref[2*MAX]; deque<pair<int,int>>kol; void dodaj(int x, int i){ while(kol.size() && kol.back().fi<x) kol.pop_back(); kol.pb({x, i}); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin>>n; for(int i=1; i<=n; i++){ cin>>t[i]; t[i+n]=t[i]; } int maxi=0; for(int i=1; i<=2*n; i++) pref[i]=pref[i-1]+t[i]; for(int i=2; i<=n-(n/2)+1; i++) dodaj(pref[i+n/2-1]-pref[i-1], i); int l=n-(n/2)+1; for(int i=1; i<=n; i++){ while(kol.size()&&kol.front().se<=i) kol.pop_front(); //cout<<i<<": "<<l+(n/2)-1<<" "<<l-1<<" "<<pref[l+(n/2)-1]-pref[l-1]<<"\n"; dodaj(pref[l+(n/2)-1]-pref[l-1], l); l++; //cout<<kol.front().fi<<" "<<kol.front().se<<"\n"; maxi=max(maxi, pref[n]-kol.front().fi); } cout<<maxi<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...