Submission #486588

#TimeUsernameProblemLanguageResultExecution timeMemory
486588ez_ioiCandies (JOI18_candies)C++17
0 / 100
5094 ms332 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int mxN = 2e5 + 5, mod = 1e9 + 7, LOG = 20;

int n, a[mxN];
ll p[mxN], res[mxN];
pair <ll, int> dp[mxN];

int main() {
	ios :: sync_with_stdio(false), cin.tie(nullptr);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	dp[1] = {a[1], 1};
	for (int i = 2; i <= n; ++i) {
		if (dp[i - 1].first >= dp[i - 2].first + a[i]) {
			p[i] = dp[i - 1].second;
			dp[i] = dp[i - 1];
		}
		else {
			p[i] = dp[i - 2].second;
			dp[i] = {dp[i - 2].first + a[i], i}; 
		}
	}
	int now = dp[n].second;
	multiset <int> lmao;
	ll ans = 0; 
	while (now) {
		ans += a[now];
		lmao.insert(a[now]);
		now = p[now];
	}
	if (n & 1) {
		if ((int)lmao.size() < (n + 1) / 2) {
			ll bruh = 0;
			for (int i = 1; i <= n; i += 2) bruh += a[i];
			res[(n + 1) / 2] = bruh;
		}
	}
	for (int i = n / 2; i > 0; i--) {
		res[i] = ans;
		ans -= *lmao.begin();
		lmao.erase(lmao.begin());
	}
	for (int i = 1; i <= (n + 1) / 2; ++i) cout << res[i] << '\n';
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...