Submission #251760

#TimeUsernameProblemLanguageResultExecution timeMemory
251760tutisHacker (BOI15_hac)C++17
100 / 100
382 ms29920 KiB
/*input
4
7 6 8 4
*/
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename K>
using ordered_map = tree<T, K, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	ll h[n];
	for (int i = 0; i < n; i++)
		cin >> h[i];
	ll s[2 * n + 1];
	s[0] = h[0];
	for (int i = 1; i <= 2 * n; i++)
		s[i] = s[i - 1] + h[i % n];
	ll k = (n + 1) / 2;
	vector<ll>X;
	for (int i = k; i <= 2 * n; i++)
		X.push_back(s[i] - s[i - k]);
	multiset<ll>A;
	for (int i = 0; i < k; i++)
		A.insert(X[i]);
	ll ans = *A.begin();
	for (int i = k; i < (int)X.size(); i++)
	{
		A.insert(X[i]);
		A.erase(A.find(X[i - k]));
		ans = max(ans, *A.begin());
	}
	cout << ans << "\n";
	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...