# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47801 | 2018-05-07T10:25:43 Z | square1001 | Fireworks (APIO16_fireworks) | C++14 | 20 ms | 21876 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); } int va = *it; it = --v[id[i]].erase(it); int 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 | 18 ms | 21496 KB | Output is correct |
2 | Correct | 18 ms | 21612 KB | Output is correct |
3 | Correct | 19 ms | 21612 KB | Output is correct |
4 | Correct | 19 ms | 21612 KB | Output is correct |
5 | Correct | 18 ms | 21644 KB | Output is correct |
6 | Correct | 19 ms | 21644 KB | Output is correct |
7 | Correct | 18 ms | 21772 KB | Output is correct |
8 | Correct | 18 ms | 21772 KB | Output is correct |
9 | Correct | 19 ms | 21772 KB | Output is correct |
10 | Correct | 18 ms | 21772 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 21772 KB | Output is correct |
2 | Correct | 19 ms | 21772 KB | Output is correct |
3 | Correct | 19 ms | 21772 KB | Output is correct |
4 | Correct | 19 ms | 21772 KB | Output is correct |
5 | Correct | 19 ms | 21772 KB | Output is correct |
6 | Correct | 19 ms | 21876 KB | Output is correct |
7 | Correct | 18 ms | 21876 KB | Output is correct |
8 | Correct | 18 ms | 21876 KB | Output is correct |
9 | Correct | 20 ms | 21876 KB | Output is correct |
10 | Correct | 19 ms | 21876 KB | Output is correct |
11 | Correct | 19 ms | 21876 KB | Output is correct |
12 | Correct | 19 ms | 21876 KB | Output is correct |
13 | Correct | 18 ms | 21876 KB | Output is correct |
14 | Correct | 19 ms | 21876 KB | Output is correct |
15 | Correct | 19 ms | 21876 KB | Output is correct |
16 | Correct | 19 ms | 21876 KB | Output is correct |
17 | Correct | 19 ms | 21876 KB | Output is correct |
18 | Correct | 19 ms | 21876 KB | Output is correct |
19 | Correct | 19 ms | 21876 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 21496 KB | Output is correct |
2 | Correct | 18 ms | 21612 KB | Output is correct |
3 | Correct | 19 ms | 21612 KB | Output is correct |
4 | Correct | 19 ms | 21612 KB | Output is correct |
5 | Correct | 18 ms | 21644 KB | Output is correct |
6 | Correct | 19 ms | 21644 KB | Output is correct |
7 | Correct | 18 ms | 21772 KB | Output is correct |
8 | Correct | 18 ms | 21772 KB | Output is correct |
9 | Correct | 19 ms | 21772 KB | Output is correct |
10 | Correct | 18 ms | 21772 KB | Output is correct |
11 | Correct | 18 ms | 21772 KB | Output is correct |
12 | Correct | 19 ms | 21772 KB | Output is correct |
13 | Correct | 19 ms | 21772 KB | Output is correct |
14 | Correct | 19 ms | 21772 KB | Output is correct |
15 | Correct | 19 ms | 21772 KB | Output is correct |
16 | Correct | 19 ms | 21876 KB | Output is correct |
17 | Correct | 18 ms | 21876 KB | Output is correct |
18 | Correct | 18 ms | 21876 KB | Output is correct |
19 | Correct | 20 ms | 21876 KB | Output is correct |
20 | Correct | 19 ms | 21876 KB | Output is correct |
21 | Correct | 19 ms | 21876 KB | Output is correct |
22 | Correct | 19 ms | 21876 KB | Output is correct |
23 | Correct | 18 ms | 21876 KB | Output is correct |
24 | Correct | 19 ms | 21876 KB | Output is correct |
25 | Correct | 19 ms | 21876 KB | Output is correct |
26 | Correct | 19 ms | 21876 KB | Output is correct |
27 | Correct | 19 ms | 21876 KB | Output is correct |
28 | Correct | 19 ms | 21876 KB | Output is correct |
29 | Correct | 19 ms | 21876 KB | Output is correct |
30 | Incorrect | 20 ms | 21876 KB | Output isn't correct |
31 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 21496 KB | Output is correct |
2 | Correct | 18 ms | 21612 KB | Output is correct |
3 | Correct | 19 ms | 21612 KB | Output is correct |
4 | Correct | 19 ms | 21612 KB | Output is correct |
5 | Correct | 18 ms | 21644 KB | Output is correct |
6 | Correct | 19 ms | 21644 KB | Output is correct |
7 | Correct | 18 ms | 21772 KB | Output is correct |
8 | Correct | 18 ms | 21772 KB | Output is correct |
9 | Correct | 19 ms | 21772 KB | Output is correct |
10 | Correct | 18 ms | 21772 KB | Output is correct |
11 | Correct | 18 ms | 21772 KB | Output is correct |
12 | Correct | 19 ms | 21772 KB | Output is correct |
13 | Correct | 19 ms | 21772 KB | Output is correct |
14 | Correct | 19 ms | 21772 KB | Output is correct |
15 | Correct | 19 ms | 21772 KB | Output is correct |
16 | Correct | 19 ms | 21876 KB | Output is correct |
17 | Correct | 18 ms | 21876 KB | Output is correct |
18 | Correct | 18 ms | 21876 KB | Output is correct |
19 | Correct | 20 ms | 21876 KB | Output is correct |
20 | Correct | 19 ms | 21876 KB | Output is correct |
21 | Correct | 19 ms | 21876 KB | Output is correct |
22 | Correct | 19 ms | 21876 KB | Output is correct |
23 | Correct | 18 ms | 21876 KB | Output is correct |
24 | Correct | 19 ms | 21876 KB | Output is correct |
25 | Correct | 19 ms | 21876 KB | Output is correct |
26 | Correct | 19 ms | 21876 KB | Output is correct |
27 | Correct | 19 ms | 21876 KB | Output is correct |
28 | Correct | 19 ms | 21876 KB | Output is correct |
29 | Correct | 19 ms | 21876 KB | Output is correct |
30 | Incorrect | 20 ms | 21876 KB | Output isn't correct |
31 | Halted | 0 ms | 0 KB | - |