답안 #516440

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
516440 2022-01-21T10:09:46 Z Leonardo_Paes Candies (JOI18_candies) C++17
0 / 100
2 ms 576 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 576 KB Output isn't correct
2 Halted 0 ms 0 KB -