Submission #893127

#TimeUsernameProblemLanguageResultExecution timeMemory
893127LCJLYHacker (BOI15_hac)C++14
100 / 100
55 ms25704 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;
	int mini[n];
	for(int x=0;x<n;x++) mini[x]=1e17;
	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())mini[x%n]=min(mini[x%n],d.front().first);
	}
	for(int x=0;x<n;x++) best=max(best,mini[x]);
	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...