제출 #516440

#제출 시각아이디문제언어결과실행 시간메모리
516440Leonardo_PaesCandies (JOI18_candies)C++17
0 / 100
2 ms576 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
#define f first
#define s second
const ll inf = 1e18;

int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n;
	cin >> n;
	set<pii> s, ord;
	for(int i=1; i<=n; i++){
		int x;
		cin >> x;
		s.insert({-x, i});
		ord.insert({i, -x});
	}
	ll ans = 0;
	for(int i=0; i<((n+1)>>1); i++){
		auto x = s.begin();
		pii v = *x;
		s.erase(x);
		ans -= v.f;
		cout << ans << "\n";
		auto p = ord.lower_bound({x->s, -inf});
		if(p != ord.begin()){
			auto viz = p;
			--viz;
			v.f -= viz->s;
			s.erase(s.lower_bound({viz->s, -inf}));
			ord.erase(viz);
		}
		if(p->f != ord.rbegin()->f){
			auto viz = p;
			++viz;
			v.f -= viz->s;
			s.erase(s.lower_bound({viz->s, -inf}));
			ord.erase(viz);
		}
		v.f *=-1;
		ord.erase(p);
		ord.insert({v.s, v.f});
		s.insert(v);
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...