Submission #705640

#TimeUsernameProblemLanguageResultExecution timeMemory
705640Markomafko972Hacker (BOI15_hac)C++14
100 / 100
59 ms21340 KiB
#include <bits/stdc++.h>
#define X first
#define Y second
#define pb push_back
#define pii pair<int, int>
typedef long long ll;
using namespace std;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int OFF = (1 << 20);

int n;
int a[1500005];
ll pref[1500005];
deque<int> d;

void ubaci(int x) {
	while (d.size() > 0 && d.back() > x) d.pop_back();
	d.push_back(x);
}

void izbaci(int x) {
	if (d.size() > 0 && d.front() == x) d.pop_front();
}

int main () {

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		a[i+n] = a[i];
		a[i+2*n] = a[i];
	}
	for (int i = 1; i <= 3*n; i++) pref[i] = pref[i-1] + a[i];

	for (int i = n; i-(n+1)/2+1 <= n; i++) ubaci(pref[i]-pref[i-(n+1)/2]);
	int sol = d.front();

	for (int i = n+1; i <= 2*n; i++) {
		izbaci(pref[i-1]-pref[i-1-(n+1)/2]);
		ubaci(pref[i+(n+1)/2-1]-pref[i-1]);
		sol = max(sol, d.front());
	}
	cout << sol;

	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...