# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47802 | 2018-05-07T10:26:18 Z | square1001 | Fireworks (APIO16_fireworks) | C++14 | 702 ms | 101032 KB |
#include <set> #include <vector> #include <iostream> #include <algorithm> using namespace std; int N, M, p[300009], c[300009], id[300009]; vector<int> g[300009]; multiset<long long> v[300009]; int main() { cin.tie(0); ios_base::sync_with_stdio(false); cin >> N >> M; long long sum = 0; for (int i = 1; i < N + M; i++) { cin >> p[i] >> c[i]; g[--p[i]].push_back(i); sum += c[i]; if (i >= N) { v[i - N].insert(c[i]); v[i - N].insert(c[i]); id[i] = i - N; } } for (int i = N - 1; i >= 0; i--) { int mx = 0; for (int j : g[i]) { if (mx < v[id[j]].size()) { mx = v[id[j]].size(); id[i] = id[j]; } } for (int j : g[i]) { if (id[j] != id[i]) { int sz = v[id[i]].size(); v[id[i]].insert(v[id[j]].begin(), v[id[j]].end()); } } multiset<long long>::iterator it = --v[id[i]].end(); for (int j = 1; j < g[i].size(); j++) { it = --v[id[i]].erase(it); } long long va = *it; it = --v[id[i]].erase(it); long long vb = *it; it = --v[id[i]].erase(it); v[id[i]].insert(va + c[i]); v[id[i]].insert(vb + c[i]); } vector<long long> res(v[id[0]].begin(), v[id[0]].end()); for (int i = 0; i < res.size(); i++) { sum -= (res[i] - (i == 0 ? 0 : res[i - 1])) * (res.size() - i - 1); } cout << sum << '\n'; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 21500 KB | Output is correct |
2 | Correct | 22 ms | 21604 KB | Output is correct |
3 | Correct | 18 ms | 21604 KB | Output is correct |
4 | Correct | 21 ms | 21604 KB | Output is correct |
5 | Correct | 18 ms | 21604 KB | Output is correct |
6 | Correct | 18 ms | 21616 KB | Output is correct |
7 | Correct | 18 ms | 21616 KB | Output is correct |
8 | Correct | 19 ms | 21728 KB | Output is correct |
9 | Correct | 19 ms | 21728 KB | Output is correct |
10 | Correct | 18 ms | 21728 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 21728 KB | Output is correct |
2 | Correct | 19 ms | 21784 KB | Output is correct |
3 | Correct | 19 ms | 21784 KB | Output is correct |
4 | Correct | 19 ms | 21784 KB | Output is correct |
5 | Correct | 19 ms | 21784 KB | Output is correct |
6 | Correct | 19 ms | 21784 KB | Output is correct |
7 | Correct | 18 ms | 21784 KB | Output is correct |
8 | Correct | 19 ms | 21784 KB | Output is correct |
9 | Correct | 18 ms | 21784 KB | Output is correct |
10 | Correct | 19 ms | 21784 KB | Output is correct |
11 | Correct | 19 ms | 21784 KB | Output is correct |
12 | Correct | 19 ms | 21784 KB | Output is correct |
13 | Correct | 19 ms | 21784 KB | Output is correct |
14 | Correct | 19 ms | 21784 KB | Output is correct |
15 | Correct | 21 ms | 21784 KB | Output is correct |
16 | Correct | 18 ms | 21784 KB | Output is correct |
17 | Correct | 19 ms | 21784 KB | Output is correct |
18 | Correct | 19 ms | 21784 KB | Output is correct |
19 | Correct | 19 ms | 21784 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 21500 KB | Output is correct |
2 | Correct | 22 ms | 21604 KB | Output is correct |
3 | Correct | 18 ms | 21604 KB | Output is correct |
4 | Correct | 21 ms | 21604 KB | Output is correct |
5 | Correct | 18 ms | 21604 KB | Output is correct |
6 | Correct | 18 ms | 21616 KB | Output is correct |
7 | Correct | 18 ms | 21616 KB | Output is correct |
8 | Correct | 19 ms | 21728 KB | Output is correct |
9 | Correct | 19 ms | 21728 KB | Output is correct |
10 | Correct | 18 ms | 21728 KB | Output is correct |
11 | Correct | 20 ms | 21728 KB | Output is correct |
12 | Correct | 19 ms | 21784 KB | Output is correct |
13 | Correct | 19 ms | 21784 KB | Output is correct |
14 | Correct | 19 ms | 21784 KB | Output is correct |
15 | Correct | 19 ms | 21784 KB | Output is correct |
16 | Correct | 19 ms | 21784 KB | Output is correct |
17 | Correct | 18 ms | 21784 KB | Output is correct |
18 | Correct | 19 ms | 21784 KB | Output is correct |
19 | Correct | 18 ms | 21784 KB | Output is correct |
20 | Correct | 19 ms | 21784 KB | Output is correct |
21 | Correct | 19 ms | 21784 KB | Output is correct |
22 | Correct | 19 ms | 21784 KB | Output is correct |
23 | Correct | 19 ms | 21784 KB | Output is correct |
24 | Correct | 19 ms | 21784 KB | Output is correct |
25 | Correct | 21 ms | 21784 KB | Output is correct |
26 | Correct | 18 ms | 21784 KB | Output is correct |
27 | Correct | 19 ms | 21784 KB | Output is correct |
28 | Correct | 19 ms | 21784 KB | Output is correct |
29 | Correct | 19 ms | 21784 KB | Output is correct |
30 | Correct | 18 ms | 21784 KB | Output is correct |
31 | Correct | 19 ms | 21836 KB | Output is correct |
32 | Correct | 20 ms | 21852 KB | Output is correct |
33 | Correct | 20 ms | 22004 KB | Output is correct |
34 | Correct | 28 ms | 22164 KB | Output is correct |
35 | Correct | 23 ms | 22212 KB | Output is correct |
36 | Correct | 29 ms | 22420 KB | Output is correct |
37 | Correct | 30 ms | 22584 KB | Output is correct |
38 | Correct | 23 ms | 22584 KB | Output is correct |
39 | Correct | 22 ms | 22716 KB | Output is correct |
40 | Correct | 23 ms | 22716 KB | Output is correct |
41 | Correct | 21 ms | 22716 KB | Output is correct |
42 | Correct | 21 ms | 22716 KB | Output is correct |
43 | Correct | 22 ms | 22900 KB | Output is correct |
44 | Correct | 22 ms | 23116 KB | Output is correct |
45 | Correct | 23 ms | 23172 KB | Output is correct |
46 | Correct | 24 ms | 23880 KB | Output is correct |
47 | Correct | 24 ms | 23880 KB | Output is correct |
48 | Correct | 24 ms | 23880 KB | Output is correct |
49 | Correct | 24 ms | 23880 KB | Output is correct |
50 | Correct | 23 ms | 23880 KB | Output is correct |
51 | Correct | 25 ms | 23880 KB | Output is correct |
52 | Correct | 24 ms | 23880 KB | Output is correct |
53 | Correct | 25 ms | 23932 KB | Output is correct |
54 | Correct | 24 ms | 24280 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 21500 KB | Output is correct |
2 | Correct | 22 ms | 21604 KB | Output is correct |
3 | Correct | 18 ms | 21604 KB | Output is correct |
4 | Correct | 21 ms | 21604 KB | Output is correct |
5 | Correct | 18 ms | 21604 KB | Output is correct |
6 | Correct | 18 ms | 21616 KB | Output is correct |
7 | Correct | 18 ms | 21616 KB | Output is correct |
8 | Correct | 19 ms | 21728 KB | Output is correct |
9 | Correct | 19 ms | 21728 KB | Output is correct |
10 | Correct | 18 ms | 21728 KB | Output is correct |
11 | Correct | 20 ms | 21728 KB | Output is correct |
12 | Correct | 19 ms | 21784 KB | Output is correct |
13 | Correct | 19 ms | 21784 KB | Output is correct |
14 | Correct | 19 ms | 21784 KB | Output is correct |
15 | Correct | 19 ms | 21784 KB | Output is correct |
16 | Correct | 19 ms | 21784 KB | Output is correct |
17 | Correct | 18 ms | 21784 KB | Output is correct |
18 | Correct | 19 ms | 21784 KB | Output is correct |
19 | Correct | 18 ms | 21784 KB | Output is correct |
20 | Correct | 19 ms | 21784 KB | Output is correct |
21 | Correct | 19 ms | 21784 KB | Output is correct |
22 | Correct | 19 ms | 21784 KB | Output is correct |
23 | Correct | 19 ms | 21784 KB | Output is correct |
24 | Correct | 19 ms | 21784 KB | Output is correct |
25 | Correct | 21 ms | 21784 KB | Output is correct |
26 | Correct | 18 ms | 21784 KB | Output is correct |
27 | Correct | 19 ms | 21784 KB | Output is correct |
28 | Correct | 19 ms | 21784 KB | Output is correct |
29 | Correct | 19 ms | 21784 KB | Output is correct |
30 | Correct | 18 ms | 21784 KB | Output is correct |
31 | Correct | 19 ms | 21836 KB | Output is correct |
32 | Correct | 20 ms | 21852 KB | Output is correct |
33 | Correct | 20 ms | 22004 KB | Output is correct |
34 | Correct | 28 ms | 22164 KB | Output is correct |
35 | Correct | 23 ms | 22212 KB | Output is correct |
36 | Correct | 29 ms | 22420 KB | Output is correct |
37 | Correct | 30 ms | 22584 KB | Output is correct |
38 | Correct | 23 ms | 22584 KB | Output is correct |
39 | Correct | 22 ms | 22716 KB | Output is correct |
40 | Correct | 23 ms | 22716 KB | Output is correct |
41 | Correct | 21 ms | 22716 KB | Output is correct |
42 | Correct | 21 ms | 22716 KB | Output is correct |
43 | Correct | 22 ms | 22900 KB | Output is correct |
44 | Correct | 22 ms | 23116 KB | Output is correct |
45 | Correct | 23 ms | 23172 KB | Output is correct |
46 | Correct | 24 ms | 23880 KB | Output is correct |
47 | Correct | 24 ms | 23880 KB | Output is correct |
48 | Correct | 24 ms | 23880 KB | Output is correct |
49 | Correct | 24 ms | 23880 KB | Output is correct |
50 | Correct | 23 ms | 23880 KB | Output is correct |
51 | Correct | 25 ms | 23880 KB | Output is correct |
52 | Correct | 24 ms | 23880 KB | Output is correct |
53 | Correct | 25 ms | 23932 KB | Output is correct |
54 | Correct | 24 ms | 24280 KB | Output is correct |
55 | Correct | 29 ms | 24952 KB | Output is correct |
56 | Correct | 70 ms | 30392 KB | Output is correct |
57 | Correct | 112 ms | 36212 KB | Output is correct |
58 | Correct | 164 ms | 39588 KB | Output is correct |
59 | Correct | 197 ms | 44544 KB | Output is correct |
60 | Correct | 261 ms | 49328 KB | Output is correct |
61 | Correct | 288 ms | 52780 KB | Output is correct |
62 | Correct | 330 ms | 56268 KB | Output is correct |
63 | Correct | 393 ms | 63016 KB | Output is correct |
64 | Correct | 439 ms | 63404 KB | Output is correct |
65 | Correct | 153 ms | 63404 KB | Output is correct |
66 | Correct | 155 ms | 63404 KB | Output is correct |
67 | Correct | 153 ms | 63404 KB | Output is correct |
68 | Correct | 325 ms | 63404 KB | Output is correct |
69 | Correct | 359 ms | 63404 KB | Output is correct |
70 | Correct | 369 ms | 63404 KB | Output is correct |
71 | Correct | 525 ms | 100896 KB | Output is correct |
72 | Correct | 528 ms | 101032 KB | Output is correct |
73 | Correct | 491 ms | 101032 KB | Output is correct |
74 | Correct | 494 ms | 101032 KB | Output is correct |
75 | Correct | 502 ms | 101032 KB | Output is correct |
76 | Correct | 493 ms | 101032 KB | Output is correct |
77 | Correct | 570 ms | 101032 KB | Output is correct |
78 | Correct | 581 ms | 101032 KB | Output is correct |
79 | Correct | 702 ms | 101032 KB | Output is correct |