답안 #338767

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
338767 2020-12-23T21:06:01 Z wwdd Candies (JOI18_candies) C++14
100 / 100
326 ms 13796 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
vl w;
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	ll n;
	cin >> n;
	for(int i=0;i<n;i++) {
		ll t;
		cin >> t;
		w.push_back(t);
	}
	multiset<ll,greater<ll> > bs[2],dis[2];
	ll cu = 0;
	for(int i=n-1;i>=0;i--) {
		int nu = 1-cu;
		bs[nu].insert(w[i]);
		dis[nu].insert(w[i]);
		ll dif = 0;
		while(!dis[nu].empty() && !dis[cu].empty() && (*dis[nu].begin()+dif) <= (*dis[cu].begin())) {
			auto wa = dis[nu].begin();
			auto wb = dis[cu].begin();
			dif += (*wa)-(*wb);
			bs[nu].erase(bs[nu].find(*wa));
			bs[nu].insert(*wb);
			dis[nu].erase(wa);
			dis[cu].erase(wb);
		}
		if(!dis[nu].empty()) {
			ll wa = *dis[nu].begin();
			bs[nu].insert(wa+dif);
			dis[nu].insert(wa+dif);
			bs[nu].erase(bs[nu].find(wa));
			dis[nu].erase(dis[nu].find(wa));
		}
		cu = nu;
	}
	ll ru = 0;
	for(auto& it: bs[cu]) {
		ru += it;
		cout << ru << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 3 ms 492 KB Output is correct
12 Correct 3 ms 492 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 3 ms 492 KB Output is correct
12 Correct 3 ms 492 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 311 ms 13540 KB Output is correct
22 Correct 311 ms 13600 KB Output is correct
23 Correct 326 ms 13540 KB Output is correct
24 Correct 224 ms 13668 KB Output is correct
25 Correct 190 ms 13540 KB Output is correct
26 Correct 194 ms 13720 KB Output is correct
27 Correct 262 ms 13668 KB Output is correct
28 Correct 264 ms 13540 KB Output is correct
29 Correct 262 ms 13616 KB Output is correct
30 Correct 270 ms 13788 KB Output is correct
31 Correct 267 ms 13756 KB Output is correct
32 Correct 262 ms 13540 KB Output is correct
33 Correct 301 ms 13540 KB Output is correct
34 Correct 308 ms 13580 KB Output is correct
35 Correct 299 ms 13668 KB Output is correct
36 Correct 311 ms 13540 KB Output is correct
37 Correct 303 ms 13540 KB Output is correct
38 Correct 309 ms 13540 KB Output is correct
39 Correct 191 ms 13540 KB Output is correct
40 Correct 193 ms 13540 KB Output is correct
41 Correct 193 ms 13540 KB Output is correct
42 Correct 255 ms 13796 KB Output is correct
43 Correct 260 ms 13668 KB Output is correct
44 Correct 258 ms 13540 KB Output is correct
45 Correct 268 ms 13540 KB Output is correct
46 Correct 263 ms 13540 KB Output is correct
47 Correct 267 ms 13540 KB Output is correct
48 Correct 298 ms 13668 KB Output is correct
49 Correct 300 ms 13540 KB Output is correct
50 Correct 308 ms 13584 KB Output is correct