Submission #24138

# Submission time Handle Problem Language Result Execution time Memory
24138 2017-05-31T13:18:29 Z khsoo01 Fireworks (APIO16_fireworks) C++11
100 / 100
673 ms 53576 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m, p[300005], l[300005];

struct hull {
	ll p, i;
	multiset<ll> s;
} h[300005];

ll Pop (hull &A) {
	auto T = A.s.end(); T--;
	ll ret = *T;
	A.s.erase(T);
	return ret;
}

int main()
{
	scanf("%lld%lld",&n,&m);
	for(int i=2;i<=n;i++) {
		scanf("%lld%lld",&p[i],&l[i]);
	}
	for(int i=1;i<=m;i++) {
		ll P, L;
		scanf("%lld%lld",&P,&L);
		h[P].i--;
		h[P].p += L;
		h[P].s.insert(L);
		h[P].s.insert(L);
	}
	for(int i=n;i>=2;i--) {
		while(h[i].s.size() > 1-h[i].i) Pop(h[i]);
		h[i].p += l[i];
		ll A = Pop(h[i]), B = Pop(h[i]);
		h[i].s.insert(A + l[i]);
		h[i].s.insert(B + l[i]);
		if(p[i] != 1 && h[p[i]].s.size() < h[i].s.size()) swap(h[p[i]], h[i]);
		while(!h[i].s.empty()) h[p[i]].s.insert(Pop(h[i]));
		h[p[i]].p += h[i].p;
		h[p[i]].i += h[i].i;
	}
	ll ans = h[1].p, cur = 0, grd = h[1].i;
	while(grd < 0) {
		ll nxt = (*h[1].s.begin());
		h[1].s.erase(h[1].s.begin());
		ans += grd * (nxt - cur);
		cur = nxt; grd++;
	}
	printf("%lld\n",ans);
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:33:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(h[i].s.size() > 1-h[i].i) Pop(h[i]);
                       ^
fireworks.cpp:20:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld",&n,&m);
                         ^
fireworks.cpp:22:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld",&p[i],&l[i]);
                                ^
fireworks.cpp:26:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld",&P,&L);
                          ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 25460 KB Output is correct
2 Correct 3 ms 25460 KB Output is correct
3 Correct 6 ms 25460 KB Output is correct
4 Correct 3 ms 25460 KB Output is correct
5 Correct 0 ms 25460 KB Output is correct
6 Correct 6 ms 25460 KB Output is correct
7 Correct 6 ms 25460 KB Output is correct
8 Correct 6 ms 25460 KB Output is correct
9 Correct 6 ms 25460 KB Output is correct
10 Correct 3 ms 25460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 25460 KB Output is correct
2 Correct 6 ms 25460 KB Output is correct
3 Correct 0 ms 25460 KB Output is correct
4 Correct 0 ms 25460 KB Output is correct
5 Correct 6 ms 25460 KB Output is correct
6 Correct 3 ms 25460 KB Output is correct
7 Correct 3 ms 25460 KB Output is correct
8 Correct 6 ms 25460 KB Output is correct
9 Correct 6 ms 25460 KB Output is correct
10 Correct 6 ms 25460 KB Output is correct
11 Correct 3 ms 25460 KB Output is correct
12 Correct 3 ms 25460 KB Output is correct
13 Correct 6 ms 25460 KB Output is correct
14 Correct 3 ms 25460 KB Output is correct
15 Correct 3 ms 25460 KB Output is correct
16 Correct 9 ms 25460 KB Output is correct
17 Correct 9 ms 25460 KB Output is correct
18 Correct 6 ms 25460 KB Output is correct
19 Correct 3 ms 25460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 25460 KB Output is correct
2 Correct 3 ms 25460 KB Output is correct
3 Correct 6 ms 25460 KB Output is correct
4 Correct 3 ms 25460 KB Output is correct
5 Correct 0 ms 25460 KB Output is correct
6 Correct 6 ms 25460 KB Output is correct
7 Correct 6 ms 25460 KB Output is correct
8 Correct 6 ms 25460 KB Output is correct
9 Correct 6 ms 25460 KB Output is correct
10 Correct 3 ms 25460 KB Output is correct
11 Correct 6 ms 25460 KB Output is correct
12 Correct 6 ms 25460 KB Output is correct
13 Correct 0 ms 25460 KB Output is correct
14 Correct 0 ms 25460 KB Output is correct
15 Correct 6 ms 25460 KB Output is correct
16 Correct 3 ms 25460 KB Output is correct
17 Correct 3 ms 25460 KB Output is correct
18 Correct 6 ms 25460 KB Output is correct
19 Correct 6 ms 25460 KB Output is correct
20 Correct 6 ms 25460 KB Output is correct
21 Correct 3 ms 25460 KB Output is correct
22 Correct 3 ms 25460 KB Output is correct
23 Correct 6 ms 25460 KB Output is correct
24 Correct 3 ms 25460 KB Output is correct
25 Correct 3 ms 25460 KB Output is correct
26 Correct 9 ms 25460 KB Output is correct
27 Correct 9 ms 25460 KB Output is correct
28 Correct 6 ms 25460 KB Output is correct
29 Correct 3 ms 25460 KB Output is correct
30 Correct 6 ms 25460 KB Output is correct
31 Correct 3 ms 25460 KB Output is correct
32 Correct 6 ms 25460 KB Output is correct
33 Correct 6 ms 25592 KB Output is correct
34 Correct 6 ms 25592 KB Output is correct
35 Correct 9 ms 25592 KB Output is correct
36 Correct 13 ms 25592 KB Output is correct
37 Correct 6 ms 25592 KB Output is correct
38 Correct 9 ms 25592 KB Output is correct
39 Correct 6 ms 25592 KB Output is correct
40 Correct 3 ms 25460 KB Output is correct
41 Correct 19 ms 25460 KB Output is correct
42 Correct 9 ms 25460 KB Output is correct
43 Correct 6 ms 25724 KB Output is correct
44 Correct 6 ms 25724 KB Output is correct
45 Correct 9 ms 25724 KB Output is correct
46 Correct 13 ms 25988 KB Output is correct
47 Correct 9 ms 25988 KB Output is correct
48 Correct 6 ms 25856 KB Output is correct
49 Correct 6 ms 25988 KB Output is correct
50 Correct 6 ms 25856 KB Output is correct
51 Correct 6 ms 25856 KB Output is correct
52 Correct 6 ms 25856 KB Output is correct
53 Correct 9 ms 25856 KB Output is correct
54 Correct 6 ms 25988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 25460 KB Output is correct
2 Correct 3 ms 25460 KB Output is correct
3 Correct 6 ms 25460 KB Output is correct
4 Correct 3 ms 25460 KB Output is correct
5 Correct 0 ms 25460 KB Output is correct
6 Correct 6 ms 25460 KB Output is correct
7 Correct 6 ms 25460 KB Output is correct
8 Correct 6 ms 25460 KB Output is correct
9 Correct 6 ms 25460 KB Output is correct
10 Correct 3 ms 25460 KB Output is correct
11 Correct 6 ms 25460 KB Output is correct
12 Correct 6 ms 25460 KB Output is correct
13 Correct 0 ms 25460 KB Output is correct
14 Correct 0 ms 25460 KB Output is correct
15 Correct 6 ms 25460 KB Output is correct
16 Correct 3 ms 25460 KB Output is correct
17 Correct 3 ms 25460 KB Output is correct
18 Correct 6 ms 25460 KB Output is correct
19 Correct 6 ms 25460 KB Output is correct
20 Correct 6 ms 25460 KB Output is correct
21 Correct 3 ms 25460 KB Output is correct
22 Correct 3 ms 25460 KB Output is correct
23 Correct 6 ms 25460 KB Output is correct
24 Correct 3 ms 25460 KB Output is correct
25 Correct 3 ms 25460 KB Output is correct
26 Correct 9 ms 25460 KB Output is correct
27 Correct 9 ms 25460 KB Output is correct
28 Correct 6 ms 25460 KB Output is correct
29 Correct 3 ms 25460 KB Output is correct
30 Correct 6 ms 25460 KB Output is correct
31 Correct 3 ms 25460 KB Output is correct
32 Correct 6 ms 25460 KB Output is correct
33 Correct 6 ms 25592 KB Output is correct
34 Correct 6 ms 25592 KB Output is correct
35 Correct 9 ms 25592 KB Output is correct
36 Correct 13 ms 25592 KB Output is correct
37 Correct 6 ms 25592 KB Output is correct
38 Correct 9 ms 25592 KB Output is correct
39 Correct 6 ms 25592 KB Output is correct
40 Correct 3 ms 25460 KB Output is correct
41 Correct 19 ms 25460 KB Output is correct
42 Correct 9 ms 25460 KB Output is correct
43 Correct 6 ms 25724 KB Output is correct
44 Correct 6 ms 25724 KB Output is correct
45 Correct 9 ms 25724 KB Output is correct
46 Correct 13 ms 25988 KB Output is correct
47 Correct 9 ms 25988 KB Output is correct
48 Correct 6 ms 25856 KB Output is correct
49 Correct 6 ms 25988 KB Output is correct
50 Correct 6 ms 25856 KB Output is correct
51 Correct 6 ms 25856 KB Output is correct
52 Correct 6 ms 25856 KB Output is correct
53 Correct 9 ms 25856 KB Output is correct
54 Correct 6 ms 25988 KB Output is correct
55 Correct 19 ms 25988 KB Output is correct
56 Correct 46 ms 27176 KB Output is correct
57 Correct 79 ms 28364 KB Output is correct
58 Correct 123 ms 29156 KB Output is correct
59 Correct 199 ms 30476 KB Output is correct
60 Correct 246 ms 31664 KB Output is correct
61 Correct 303 ms 32456 KB Output is correct
62 Correct 309 ms 33248 KB Output is correct
63 Correct 469 ms 34700 KB Output is correct
64 Correct 483 ms 35228 KB Output is correct
65 Correct 116 ms 25460 KB Output is correct
66 Correct 116 ms 25460 KB Output is correct
67 Correct 143 ms 25592 KB Output is correct
68 Correct 373 ms 39584 KB Output is correct
69 Correct 409 ms 39716 KB Output is correct
70 Correct 396 ms 39716 KB Output is correct
71 Correct 586 ms 53312 KB Output is correct
72 Correct 543 ms 53312 KB Output is correct
73 Correct 449 ms 53576 KB Output is correct
74 Correct 519 ms 53576 KB Output is correct
75 Correct 523 ms 53312 KB Output is correct
76 Correct 476 ms 53444 KB Output is correct
77 Correct 503 ms 52784 KB Output is correct
78 Correct 606 ms 52916 KB Output is correct
79 Correct 673 ms 53576 KB Output is correct