Submission #252465

#TimeUsernameProblemLanguageResultExecution timeMemory
252465BlagojceHacker (BOI15_hac)C++11
100 / 100
119 ms22888 KiB
#include <bits/stdc++.h> 
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
#include <time.h>
#include <cmath>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

const int i_inf = 1e9;
const ll inf = 1e18;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi  = 3.14159265359;
 
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 5e5;


void solve(){
	int n;
	cin >> n;
	int a[2*n];
	fr(i, 0, n){
		cin >> a[i];
		a[i+n] = a[i];
	}
	int len = (n+1)/2;
	
	n*=2;
	int pre[n];
	pre[0] = a[0];
	fr(i, 1, n){
		pre[i] = pre[i-1]+a[i];
	}
	int sum[n];
	memset(sum, 0, sizeof(sum));
	fr(i, len-1, n){
		int s = pre[i];
		if(i-len >= 0) s -= pre[i-len];
		sum[i-len+1] = s;
		
	}
	int ans = 0;
	pq<pii> Q;
	
	fr(i, 0, n){
		Q.push({-sum[i], i});
		while(!Q.empty() && Q.top().nd <= i-len) Q.pop();
		if(i >= len-1) ans = max(ans, -	Q.top().st);
	}
	cout<<ans<<endl;
}
int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	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...