Submission #893114

#TimeUsernameProblemLanguageResultExecution timeMemory
893114LCJLYHacker (BOI15_hac)C++14
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define show(x,y) cout << y << " " << #x << endl; #define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl; #define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl; #define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl; typedef pair<int,int>pii; typedef pair<pii,pii>pi2; void solve(){ int n; cin >> n; int arr[2*n+1]; for(int x=1;x<=n;x++){ cin >> arr[x]; arr[x+n]=arr[x]; } int prefix[2*n+1]; memset(prefix,0,sizeof(prefix)); for(int x=1;x<=2*n;x++){ prefix[x]=prefix[x-1]+arr[x]; } int k=(n+1)/2; int ptr=k; deque<pii>d; int best=0; for(int x=1;x<=2*n;x++){ while(ptr<=2*n&&ptr<=x+k-1){ while(!d.empty()&&d.back().first>prefix[ptr]-prefix[ptr-k]){ d.pop_back(); } d.push_back({prefix[ptr]-prefix[ptr-k],ptr}); ptr++; } while(!d.empty()&&d.front().second<x) d.pop_front(); if(!d.empty())best=max(best,d.front().first); } cout << best; } int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); //freopen("in.txt", "r", stdin); int t=1; //cin >> t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...