Submission #962606

# Submission time Handle Problem Language Result Execution time Memory
962606 2024-04-14T02:13:07 Z pavement Candies (JOI18_candies) C++17
0 / 100
2 ms 600 KB
#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back

using ll = long long;
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
using ld = long double;

int N, A[200005];
ll ans;
multiset<pair<ll, ll> > s, s2;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		s2.emplace(A[i], i);
		s.emplace(i, A[i]);
	}
	for (int j = 1; j <= (N + 1) / 2; j++) {
		vector<set<pair<ll, ll> >::iterator> to_erase, to_erase2;
		auto [x, idx] = *s2.rbegin();
		ans += x;
		auto it = s.find(mp(idx, x));
		x = -x;
		to_erase.pb(it);
		to_erase2.pb(--s2.end());
		++it;
		if (it != s.end()) {
			to_erase.pb(it);
			to_erase2.pb(s2.find(mp(it->second, it->first)));
			x += it->second;
		}
		--it;
		if (it != s.begin()) {
			--it;
			to_erase.pb(it);
			to_erase2.pb(s2.find(mp(it->second, it->first)));
			x += it->second;
			++it;
		}
		s.emplace(idx, x);
		s2.emplace(x, idx);
		for (auto it_2 : to_erase) {
			s.erase(it_2);
		}
		for (auto it_2 : to_erase2) {
			s2.erase(it_2);
		}
		cout << ans << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -