# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1081199 |
2024-08-29T19:38:05 Z |
anton |
Jobs (BOI24_jobs) |
C++17 |
|
345 ms |
90816 KB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
const int MAX_N = 3e5+1;
int N, S;
pii merge_ev(pii a,pii b){
return {min(a.first, b.first+a.second), a.second+b.second};
}
struct Investment{
priority_queue<pii> ev;
int delta= 0;
void insert(pii e){
ev.push({e.first-delta, e.second-delta});
}
void merge(Investment b){
while(b.ev.size()>0){
auto e = b.ev.top();
b.ev.pop();
insert({e.first+b.delta, e.second+b.delta});
}
}
};
vector<vector<int>> ch;
vector<int> x;
vector<Investment> inv;
void display(Investment e){
while(e.ev.size()>0){
auto t = e.ev.top();
e.ev.pop();
}
}
void dfs(int u){
for(auto e: ch[u]){
dfs(e);
if(inv[e].ev.size()>inv[u].ev.size()){
swap(inv[e], inv[u]);
}
inv[u].merge(inv[e]);
}
pii first_elem = {min(0LL, x[u]), x[u]};
while(inv[u].ev.size()>0 && (first_elem.second<0 || first_elem.first<=inv[u].ev.top().first)){
//cout<<"merging "<<first_elem.first<<" "<<first_elem.second<<" "<<inv[u].ev.top().first<<" "<<inv[u].ev.top().second<<endl;
first_elem = merge_ev(first_elem, inv[u].ev.top());
inv[u].ev.pop();
}
if(first_elem.second>0){
inv[u].insert(first_elem);
}
//cout<<u<<endl;
//display(inv[u]);
}
signed main(){
cin>>N>>S;
x.resize(N+1, 0);
inv.resize(N+1);
ch.resize(N+1);
for(int i = 0; i<N; i++){
int p;
cin>>x[i+1]>>p;
ch[p].push_back(i+1);
}
dfs(0);
auto inv0 = inv[0];
int init_s= S;
while(inv0.ev.size()>0 && inv0.ev.top().first+S>=0){
S+= inv0.ev.top().second;
inv0.ev.pop();
}
cout<<S-init_s<<endl;
}
Compilation message
Main.cpp: In function 'void display(Investment)':
Main.cpp:38:14: warning: variable 't' set but not used [-Wunused-but-set-variable]
38 | auto t = e.ev.top();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
301 ms |
56624 KB |
Output is correct |
2 |
Correct |
252 ms |
47220 KB |
Output is correct |
3 |
Correct |
221 ms |
40980 KB |
Output is correct |
4 |
Correct |
200 ms |
56012 KB |
Output is correct |
5 |
Correct |
197 ms |
64188 KB |
Output is correct |
6 |
Correct |
157 ms |
32244 KB |
Output is correct |
7 |
Correct |
270 ms |
50120 KB |
Output is correct |
8 |
Correct |
222 ms |
41908 KB |
Output is correct |
9 |
Correct |
159 ms |
59748 KB |
Output is correct |
10 |
Correct |
188 ms |
64560 KB |
Output is correct |
11 |
Correct |
320 ms |
59240 KB |
Output is correct |
12 |
Correct |
279 ms |
48688 KB |
Output is correct |
13 |
Correct |
323 ms |
55892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
3 ms |
708 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
860 KB |
Output is correct |
12 |
Correct |
2 ms |
860 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
860 KB |
Output is correct |
18 |
Correct |
3 ms |
860 KB |
Output is correct |
19 |
Correct |
2 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
3 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
860 KB |
Output is correct |
24 |
Correct |
3 ms |
860 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
2 ms |
704 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
3 ms |
708 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
860 KB |
Output is correct |
12 |
Correct |
2 ms |
860 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
860 KB |
Output is correct |
18 |
Correct |
3 ms |
860 KB |
Output is correct |
19 |
Correct |
2 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
3 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
860 KB |
Output is correct |
24 |
Correct |
3 ms |
860 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
2 ms |
704 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
860 KB |
Output is correct |
29 |
Correct |
166 ms |
42416 KB |
Output is correct |
30 |
Correct |
167 ms |
42828 KB |
Output is correct |
31 |
Correct |
150 ms |
39868 KB |
Output is correct |
32 |
Correct |
191 ms |
90724 KB |
Output is correct |
33 |
Correct |
175 ms |
67396 KB |
Output is correct |
34 |
Correct |
173 ms |
57216 KB |
Output is correct |
35 |
Correct |
85 ms |
21444 KB |
Output is correct |
36 |
Correct |
196 ms |
49944 KB |
Output is correct |
37 |
Correct |
253 ms |
43796 KB |
Output is correct |
38 |
Correct |
190 ms |
90400 KB |
Output is correct |
39 |
Correct |
177 ms |
70004 KB |
Output is correct |
40 |
Correct |
197 ms |
51140 KB |
Output is correct |
41 |
Correct |
156 ms |
42180 KB |
Output is correct |
42 |
Correct |
91 ms |
28356 KB |
Output is correct |
43 |
Correct |
167 ms |
58308 KB |
Output is correct |
44 |
Correct |
222 ms |
90652 KB |
Output is correct |
45 |
Correct |
186 ms |
69756 KB |
Output is correct |
46 |
Correct |
181 ms |
58052 KB |
Output is correct |
47 |
Correct |
196 ms |
42176 KB |
Output is correct |
48 |
Correct |
177 ms |
41916 KB |
Output is correct |
49 |
Correct |
179 ms |
42944 KB |
Output is correct |
50 |
Correct |
213 ms |
90816 KB |
Output is correct |
51 |
Correct |
134 ms |
51536 KB |
Output is correct |
52 |
Correct |
169 ms |
50852 KB |
Output is correct |
53 |
Correct |
119 ms |
40648 KB |
Output is correct |
54 |
Correct |
180 ms |
41160 KB |
Output is correct |
55 |
Correct |
207 ms |
43196 KB |
Output is correct |
56 |
Correct |
202 ms |
90740 KB |
Output is correct |
57 |
Correct |
181 ms |
67396 KB |
Output is correct |
58 |
Correct |
220 ms |
50936 KB |
Output is correct |
59 |
Correct |
227 ms |
50300 KB |
Output is correct |
60 |
Correct |
148 ms |
41148 KB |
Output is correct |
61 |
Correct |
210 ms |
57192 KB |
Output is correct |
62 |
Correct |
217 ms |
53348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
3 ms |
708 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
860 KB |
Output is correct |
12 |
Correct |
2 ms |
860 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
860 KB |
Output is correct |
18 |
Correct |
3 ms |
860 KB |
Output is correct |
19 |
Correct |
2 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
3 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
860 KB |
Output is correct |
24 |
Correct |
3 ms |
860 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
2 ms |
704 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
860 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
2 ms |
600 KB |
Output is correct |
31 |
Correct |
3 ms |
700 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
3 ms |
860 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
2 ms |
604 KB |
Output is correct |
37 |
Correct |
3 ms |
632 KB |
Output is correct |
38 |
Correct |
1 ms |
604 KB |
Output is correct |
39 |
Correct |
2 ms |
604 KB |
Output is correct |
40 |
Correct |
1 ms |
604 KB |
Output is correct |
41 |
Correct |
2 ms |
600 KB |
Output is correct |
42 |
Correct |
2 ms |
604 KB |
Output is correct |
43 |
Correct |
2 ms |
600 KB |
Output is correct |
44 |
Correct |
2 ms |
604 KB |
Output is correct |
45 |
Correct |
2 ms |
704 KB |
Output is correct |
46 |
Correct |
2 ms |
604 KB |
Output is correct |
47 |
Correct |
2 ms |
792 KB |
Output is correct |
48 |
Correct |
3 ms |
604 KB |
Output is correct |
49 |
Correct |
1 ms |
604 KB |
Output is correct |
50 |
Correct |
2 ms |
604 KB |
Output is correct |
51 |
Correct |
1 ms |
604 KB |
Output is correct |
52 |
Correct |
1 ms |
604 KB |
Output is correct |
53 |
Correct |
3 ms |
860 KB |
Output is correct |
54 |
Correct |
3 ms |
676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
301 ms |
56624 KB |
Output is correct |
2 |
Correct |
252 ms |
47220 KB |
Output is correct |
3 |
Correct |
221 ms |
40980 KB |
Output is correct |
4 |
Correct |
200 ms |
56012 KB |
Output is correct |
5 |
Correct |
197 ms |
64188 KB |
Output is correct |
6 |
Correct |
157 ms |
32244 KB |
Output is correct |
7 |
Correct |
270 ms |
50120 KB |
Output is correct |
8 |
Correct |
222 ms |
41908 KB |
Output is correct |
9 |
Correct |
159 ms |
59748 KB |
Output is correct |
10 |
Correct |
188 ms |
64560 KB |
Output is correct |
11 |
Correct |
320 ms |
59240 KB |
Output is correct |
12 |
Correct |
279 ms |
48688 KB |
Output is correct |
13 |
Correct |
323 ms |
55892 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
860 KB |
Output is correct |
19 |
Correct |
3 ms |
708 KB |
Output is correct |
20 |
Correct |
3 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
860 KB |
Output is correct |
25 |
Correct |
2 ms |
860 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
3 ms |
860 KB |
Output is correct |
31 |
Correct |
3 ms |
860 KB |
Output is correct |
32 |
Correct |
2 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
3 ms |
600 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
2 ms |
860 KB |
Output is correct |
37 |
Correct |
3 ms |
860 KB |
Output is correct |
38 |
Correct |
2 ms |
604 KB |
Output is correct |
39 |
Correct |
2 ms |
704 KB |
Output is correct |
40 |
Correct |
1 ms |
604 KB |
Output is correct |
41 |
Correct |
2 ms |
860 KB |
Output is correct |
42 |
Correct |
166 ms |
42416 KB |
Output is correct |
43 |
Correct |
167 ms |
42828 KB |
Output is correct |
44 |
Correct |
150 ms |
39868 KB |
Output is correct |
45 |
Correct |
191 ms |
90724 KB |
Output is correct |
46 |
Correct |
175 ms |
67396 KB |
Output is correct |
47 |
Correct |
173 ms |
57216 KB |
Output is correct |
48 |
Correct |
85 ms |
21444 KB |
Output is correct |
49 |
Correct |
196 ms |
49944 KB |
Output is correct |
50 |
Correct |
253 ms |
43796 KB |
Output is correct |
51 |
Correct |
190 ms |
90400 KB |
Output is correct |
52 |
Correct |
177 ms |
70004 KB |
Output is correct |
53 |
Correct |
197 ms |
51140 KB |
Output is correct |
54 |
Correct |
156 ms |
42180 KB |
Output is correct |
55 |
Correct |
91 ms |
28356 KB |
Output is correct |
56 |
Correct |
167 ms |
58308 KB |
Output is correct |
57 |
Correct |
222 ms |
90652 KB |
Output is correct |
58 |
Correct |
186 ms |
69756 KB |
Output is correct |
59 |
Correct |
181 ms |
58052 KB |
Output is correct |
60 |
Correct |
196 ms |
42176 KB |
Output is correct |
61 |
Correct |
177 ms |
41916 KB |
Output is correct |
62 |
Correct |
179 ms |
42944 KB |
Output is correct |
63 |
Correct |
213 ms |
90816 KB |
Output is correct |
64 |
Correct |
134 ms |
51536 KB |
Output is correct |
65 |
Correct |
169 ms |
50852 KB |
Output is correct |
66 |
Correct |
119 ms |
40648 KB |
Output is correct |
67 |
Correct |
180 ms |
41160 KB |
Output is correct |
68 |
Correct |
207 ms |
43196 KB |
Output is correct |
69 |
Correct |
202 ms |
90740 KB |
Output is correct |
70 |
Correct |
181 ms |
67396 KB |
Output is correct |
71 |
Correct |
220 ms |
50936 KB |
Output is correct |
72 |
Correct |
227 ms |
50300 KB |
Output is correct |
73 |
Correct |
148 ms |
41148 KB |
Output is correct |
74 |
Correct |
210 ms |
57192 KB |
Output is correct |
75 |
Correct |
217 ms |
53348 KB |
Output is correct |
76 |
Correct |
1 ms |
344 KB |
Output is correct |
77 |
Correct |
2 ms |
600 KB |
Output is correct |
78 |
Correct |
3 ms |
700 KB |
Output is correct |
79 |
Correct |
2 ms |
604 KB |
Output is correct |
80 |
Correct |
1 ms |
604 KB |
Output is correct |
81 |
Correct |
3 ms |
860 KB |
Output is correct |
82 |
Correct |
1 ms |
604 KB |
Output is correct |
83 |
Correct |
2 ms |
604 KB |
Output is correct |
84 |
Correct |
3 ms |
632 KB |
Output is correct |
85 |
Correct |
1 ms |
604 KB |
Output is correct |
86 |
Correct |
2 ms |
604 KB |
Output is correct |
87 |
Correct |
1 ms |
604 KB |
Output is correct |
88 |
Correct |
2 ms |
600 KB |
Output is correct |
89 |
Correct |
2 ms |
604 KB |
Output is correct |
90 |
Correct |
2 ms |
600 KB |
Output is correct |
91 |
Correct |
2 ms |
604 KB |
Output is correct |
92 |
Correct |
2 ms |
704 KB |
Output is correct |
93 |
Correct |
2 ms |
604 KB |
Output is correct |
94 |
Correct |
2 ms |
792 KB |
Output is correct |
95 |
Correct |
3 ms |
604 KB |
Output is correct |
96 |
Correct |
1 ms |
604 KB |
Output is correct |
97 |
Correct |
2 ms |
604 KB |
Output is correct |
98 |
Correct |
1 ms |
604 KB |
Output is correct |
99 |
Correct |
1 ms |
604 KB |
Output is correct |
100 |
Correct |
3 ms |
860 KB |
Output is correct |
101 |
Correct |
3 ms |
676 KB |
Output is correct |
102 |
Correct |
333 ms |
53800 KB |
Output is correct |
103 |
Correct |
288 ms |
49972 KB |
Output is correct |
104 |
Correct |
270 ms |
43172 KB |
Output is correct |
105 |
Correct |
224 ms |
41196 KB |
Output is correct |
106 |
Correct |
205 ms |
65308 KB |
Output is correct |
107 |
Correct |
197 ms |
56396 KB |
Output is correct |
108 |
Correct |
344 ms |
58780 KB |
Output is correct |
109 |
Correct |
141 ms |
25288 KB |
Output is correct |
110 |
Correct |
278 ms |
44508 KB |
Output is correct |
111 |
Correct |
251 ms |
43460 KB |
Output is correct |
112 |
Correct |
289 ms |
41244 KB |
Output is correct |
113 |
Correct |
197 ms |
55864 KB |
Output is correct |
114 |
Correct |
225 ms |
66232 KB |
Output is correct |
115 |
Correct |
174 ms |
25924 KB |
Output is correct |
116 |
Correct |
331 ms |
55096 KB |
Output is correct |
117 |
Correct |
261 ms |
46300 KB |
Output is correct |
118 |
Correct |
245 ms |
43968 KB |
Output is correct |
119 |
Correct |
196 ms |
40124 KB |
Output is correct |
120 |
Correct |
194 ms |
56768 KB |
Output is correct |
121 |
Correct |
187 ms |
55940 KB |
Output is correct |
122 |
Correct |
317 ms |
63036 KB |
Output is correct |
123 |
Correct |
309 ms |
53824 KB |
Output is correct |
124 |
Correct |
226 ms |
44992 KB |
Output is correct |
125 |
Correct |
266 ms |
44740 KB |
Output is correct |
126 |
Correct |
208 ms |
41852 KB |
Output is correct |
127 |
Correct |
114 ms |
30408 KB |
Output is correct |
128 |
Correct |
79 ms |
26380 KB |
Output is correct |
129 |
Correct |
317 ms |
62844 KB |
Output is correct |
130 |
Correct |
345 ms |
53568 KB |
Output is correct |
131 |
Correct |
334 ms |
48832 KB |
Output is correct |
132 |
Correct |
252 ms |
43168 KB |
Output is correct |
133 |
Correct |
207 ms |
41148 KB |
Output is correct |
134 |
Correct |
177 ms |
65468 KB |
Output is correct |
135 |
Correct |
198 ms |
61216 KB |
Output is correct |
136 |
Correct |
341 ms |
59288 KB |
Output is correct |
137 |
Correct |
334 ms |
60264 KB |
Output is correct |