# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1066874 |
2024-08-20T08:22:40 Z |
_rain_ |
Jobs (BOI24_jobs) |
C++14 |
|
186 ms |
74440 KB |
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define debug false
const int maxn = 3e5;
i64 s;
vector<int> g[maxn+2];
int n , x[maxn+2];
struct NODE{
i64 sum;
i64 require;
bool operator > (const NODE& other) const{
if (require != other.require) return require < other.require;
return sum < other.sum;
}
};
priority_queue<NODE,vector<NODE>,greater<NODE>> bag[maxn+2];
void dfs(int u , int p){
for (auto& v : g[u]){
if (v==p) continue;
dfs(v,u);
if (bag[v].size() > bag[u].size()) swap(bag[u] , bag[v]);
while (bag[v].size()){
bag[u].push(bag[v].top());
bag[v].pop();
}
if (debug){
cout << u << " " << v << '\n';
}
}
i64 sum = x[u] , require = min(0 , x[u]);
while (bag[u].size()){
i64 x = bag[u].top().sum , y = bag[u].top().require;
if (sum < 0){
require = min(require , y + sum);
sum += x;
bag[u].pop();
}
else {
if (require < y) {
bag[u].pop();
sum += x;
}
else {
bag[u].push({sum , require});
break;
}
}
}
if (bag[u].size()==0) bag[u].push({sum , require});
if (bag[u].size()==1 && bag[u].top().sum < 0) bag[u].pop();
return;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> s;
for (int i = 1; i <= n; ++i) {
int p; cin >> x[i] >> p;
g[p].push_back(i);
}
i64 profit = 0;
dfs(0,-1);
while (bag[0].size()){
i64 x = bag[0].top().sum , y = bag[0].top().require;
if (debug){
cout << x << ' ' << y << '\n';
}
bag[0].pop();
if (s + profit + y >= 0){
profit += x;
}
}
cout << profit;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
47936 KB |
Output is correct |
2 |
Correct |
121 ms |
37968 KB |
Output is correct |
3 |
Correct |
92 ms |
32836 KB |
Output is correct |
4 |
Correct |
97 ms |
41664 KB |
Output is correct |
5 |
Correct |
86 ms |
50444 KB |
Output is correct |
6 |
Correct |
87 ms |
36132 KB |
Output is correct |
7 |
Correct |
136 ms |
41924 KB |
Output is correct |
8 |
Correct |
96 ms |
32700 KB |
Output is correct |
9 |
Correct |
87 ms |
45828 KB |
Output is correct |
10 |
Correct |
86 ms |
50436 KB |
Output is correct |
11 |
Correct |
163 ms |
50756 KB |
Output is correct |
12 |
Correct |
120 ms |
41368 KB |
Output is correct |
13 |
Correct |
160 ms |
46088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
18012 KB |
Output is correct |
2 |
Correct |
3 ms |
18012 KB |
Output is correct |
3 |
Correct |
3 ms |
18012 KB |
Output is correct |
4 |
Correct |
4 ms |
18012 KB |
Output is correct |
5 |
Correct |
3 ms |
18268 KB |
Output is correct |
6 |
Correct |
3 ms |
18268 KB |
Output is correct |
7 |
Correct |
4 ms |
18220 KB |
Output is correct |
8 |
Correct |
3 ms |
18084 KB |
Output is correct |
9 |
Correct |
3 ms |
18012 KB |
Output is correct |
10 |
Correct |
4 ms |
18012 KB |
Output is correct |
11 |
Correct |
4 ms |
18268 KB |
Output is correct |
12 |
Correct |
3 ms |
18140 KB |
Output is correct |
13 |
Correct |
4 ms |
18012 KB |
Output is correct |
14 |
Correct |
3 ms |
18136 KB |
Output is correct |
15 |
Correct |
3 ms |
18200 KB |
Output is correct |
16 |
Correct |
3 ms |
18008 KB |
Output is correct |
17 |
Correct |
4 ms |
18268 KB |
Output is correct |
18 |
Correct |
4 ms |
18284 KB |
Output is correct |
19 |
Correct |
3 ms |
18012 KB |
Output is correct |
20 |
Correct |
3 ms |
18012 KB |
Output is correct |
21 |
Correct |
3 ms |
18012 KB |
Output is correct |
22 |
Correct |
3 ms |
18012 KB |
Output is correct |
23 |
Correct |
4 ms |
18280 KB |
Output is correct |
24 |
Correct |
4 ms |
18268 KB |
Output is correct |
25 |
Correct |
3 ms |
18080 KB |
Output is correct |
26 |
Correct |
3 ms |
18076 KB |
Output is correct |
27 |
Correct |
3 ms |
18012 KB |
Output is correct |
28 |
Correct |
3 ms |
18268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
18012 KB |
Output is correct |
2 |
Correct |
3 ms |
18012 KB |
Output is correct |
3 |
Correct |
3 ms |
18012 KB |
Output is correct |
4 |
Correct |
4 ms |
18012 KB |
Output is correct |
5 |
Correct |
3 ms |
18268 KB |
Output is correct |
6 |
Correct |
3 ms |
18268 KB |
Output is correct |
7 |
Correct |
4 ms |
18220 KB |
Output is correct |
8 |
Correct |
3 ms |
18084 KB |
Output is correct |
9 |
Correct |
3 ms |
18012 KB |
Output is correct |
10 |
Correct |
4 ms |
18012 KB |
Output is correct |
11 |
Correct |
4 ms |
18268 KB |
Output is correct |
12 |
Correct |
3 ms |
18140 KB |
Output is correct |
13 |
Correct |
4 ms |
18012 KB |
Output is correct |
14 |
Correct |
3 ms |
18136 KB |
Output is correct |
15 |
Correct |
3 ms |
18200 KB |
Output is correct |
16 |
Correct |
3 ms |
18008 KB |
Output is correct |
17 |
Correct |
4 ms |
18268 KB |
Output is correct |
18 |
Correct |
4 ms |
18284 KB |
Output is correct |
19 |
Correct |
3 ms |
18012 KB |
Output is correct |
20 |
Correct |
3 ms |
18012 KB |
Output is correct |
21 |
Correct |
3 ms |
18012 KB |
Output is correct |
22 |
Correct |
3 ms |
18012 KB |
Output is correct |
23 |
Correct |
4 ms |
18280 KB |
Output is correct |
24 |
Correct |
4 ms |
18268 KB |
Output is correct |
25 |
Correct |
3 ms |
18080 KB |
Output is correct |
26 |
Correct |
3 ms |
18076 KB |
Output is correct |
27 |
Correct |
3 ms |
18012 KB |
Output is correct |
28 |
Correct |
3 ms |
18268 KB |
Output is correct |
29 |
Correct |
81 ms |
39948 KB |
Output is correct |
30 |
Correct |
74 ms |
38348 KB |
Output is correct |
31 |
Correct |
63 ms |
34868 KB |
Output is correct |
32 |
Correct |
95 ms |
72040 KB |
Output is correct |
33 |
Correct |
98 ms |
56856 KB |
Output is correct |
34 |
Correct |
84 ms |
48452 KB |
Output is correct |
35 |
Correct |
40 ms |
27468 KB |
Output is correct |
36 |
Correct |
77 ms |
41928 KB |
Output is correct |
37 |
Correct |
77 ms |
39616 KB |
Output is correct |
38 |
Correct |
93 ms |
71120 KB |
Output is correct |
39 |
Correct |
93 ms |
56392 KB |
Output is correct |
40 |
Correct |
88 ms |
45896 KB |
Output is correct |
41 |
Correct |
81 ms |
36288 KB |
Output is correct |
42 |
Correct |
39 ms |
32232 KB |
Output is correct |
43 |
Correct |
81 ms |
48580 KB |
Output is correct |
44 |
Correct |
102 ms |
74192 KB |
Output is correct |
45 |
Correct |
90 ms |
56404 KB |
Output is correct |
46 |
Correct |
102 ms |
48156 KB |
Output is correct |
47 |
Correct |
78 ms |
36288 KB |
Output is correct |
48 |
Correct |
74 ms |
38848 KB |
Output is correct |
49 |
Correct |
77 ms |
39616 KB |
Output is correct |
50 |
Correct |
97 ms |
74408 KB |
Output is correct |
51 |
Correct |
66 ms |
47980 KB |
Output is correct |
52 |
Correct |
87 ms |
46404 KB |
Output is correct |
53 |
Correct |
57 ms |
39900 KB |
Output is correct |
54 |
Correct |
68 ms |
36164 KB |
Output is correct |
55 |
Correct |
76 ms |
41028 KB |
Output is correct |
56 |
Correct |
97 ms |
74440 KB |
Output is correct |
57 |
Correct |
98 ms |
56720 KB |
Output is correct |
58 |
Correct |
91 ms |
44872 KB |
Output is correct |
59 |
Correct |
83 ms |
42436 KB |
Output is correct |
60 |
Correct |
72 ms |
37316 KB |
Output is correct |
61 |
Correct |
81 ms |
47680 KB |
Output is correct |
62 |
Correct |
92 ms |
46660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
18012 KB |
Output is correct |
2 |
Correct |
3 ms |
18012 KB |
Output is correct |
3 |
Correct |
3 ms |
18012 KB |
Output is correct |
4 |
Correct |
4 ms |
18012 KB |
Output is correct |
5 |
Correct |
3 ms |
18268 KB |
Output is correct |
6 |
Correct |
3 ms |
18268 KB |
Output is correct |
7 |
Correct |
4 ms |
18220 KB |
Output is correct |
8 |
Correct |
3 ms |
18084 KB |
Output is correct |
9 |
Correct |
3 ms |
18012 KB |
Output is correct |
10 |
Correct |
4 ms |
18012 KB |
Output is correct |
11 |
Correct |
4 ms |
18268 KB |
Output is correct |
12 |
Correct |
3 ms |
18140 KB |
Output is correct |
13 |
Correct |
4 ms |
18012 KB |
Output is correct |
14 |
Correct |
3 ms |
18136 KB |
Output is correct |
15 |
Correct |
3 ms |
18200 KB |
Output is correct |
16 |
Correct |
3 ms |
18008 KB |
Output is correct |
17 |
Correct |
4 ms |
18268 KB |
Output is correct |
18 |
Correct |
4 ms |
18284 KB |
Output is correct |
19 |
Correct |
3 ms |
18012 KB |
Output is correct |
20 |
Correct |
3 ms |
18012 KB |
Output is correct |
21 |
Correct |
3 ms |
18012 KB |
Output is correct |
22 |
Correct |
3 ms |
18012 KB |
Output is correct |
23 |
Correct |
4 ms |
18280 KB |
Output is correct |
24 |
Correct |
4 ms |
18268 KB |
Output is correct |
25 |
Correct |
3 ms |
18080 KB |
Output is correct |
26 |
Correct |
3 ms |
18076 KB |
Output is correct |
27 |
Correct |
3 ms |
18012 KB |
Output is correct |
28 |
Correct |
3 ms |
18268 KB |
Output is correct |
29 |
Correct |
3 ms |
18012 KB |
Output is correct |
30 |
Correct |
4 ms |
18012 KB |
Output is correct |
31 |
Correct |
4 ms |
18008 KB |
Output is correct |
32 |
Correct |
4 ms |
18012 KB |
Output is correct |
33 |
Correct |
4 ms |
18012 KB |
Output is correct |
34 |
Correct |
4 ms |
18268 KB |
Output is correct |
35 |
Correct |
4 ms |
18268 KB |
Output is correct |
36 |
Correct |
4 ms |
18012 KB |
Output is correct |
37 |
Correct |
4 ms |
18012 KB |
Output is correct |
38 |
Correct |
3 ms |
18012 KB |
Output is correct |
39 |
Correct |
4 ms |
18012 KB |
Output is correct |
40 |
Correct |
3 ms |
18268 KB |
Output is correct |
41 |
Correct |
4 ms |
18012 KB |
Output is correct |
42 |
Correct |
3 ms |
18096 KB |
Output is correct |
43 |
Correct |
4 ms |
18108 KB |
Output is correct |
44 |
Correct |
4 ms |
18008 KB |
Output is correct |
45 |
Correct |
3 ms |
18028 KB |
Output is correct |
46 |
Correct |
3 ms |
18268 KB |
Output is correct |
47 |
Correct |
4 ms |
18264 KB |
Output is correct |
48 |
Correct |
3 ms |
18012 KB |
Output is correct |
49 |
Correct |
3 ms |
18008 KB |
Output is correct |
50 |
Correct |
3 ms |
18012 KB |
Output is correct |
51 |
Correct |
3 ms |
18012 KB |
Output is correct |
52 |
Correct |
3 ms |
18012 KB |
Output is correct |
53 |
Correct |
3 ms |
18292 KB |
Output is correct |
54 |
Correct |
3 ms |
18012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
47936 KB |
Output is correct |
2 |
Correct |
121 ms |
37968 KB |
Output is correct |
3 |
Correct |
92 ms |
32836 KB |
Output is correct |
4 |
Correct |
97 ms |
41664 KB |
Output is correct |
5 |
Correct |
86 ms |
50444 KB |
Output is correct |
6 |
Correct |
87 ms |
36132 KB |
Output is correct |
7 |
Correct |
136 ms |
41924 KB |
Output is correct |
8 |
Correct |
96 ms |
32700 KB |
Output is correct |
9 |
Correct |
87 ms |
45828 KB |
Output is correct |
10 |
Correct |
86 ms |
50436 KB |
Output is correct |
11 |
Correct |
163 ms |
50756 KB |
Output is correct |
12 |
Correct |
120 ms |
41368 KB |
Output is correct |
13 |
Correct |
160 ms |
46088 KB |
Output is correct |
14 |
Correct |
3 ms |
18012 KB |
Output is correct |
15 |
Correct |
3 ms |
18012 KB |
Output is correct |
16 |
Correct |
3 ms |
18012 KB |
Output is correct |
17 |
Correct |
4 ms |
18012 KB |
Output is correct |
18 |
Correct |
3 ms |
18268 KB |
Output is correct |
19 |
Correct |
3 ms |
18268 KB |
Output is correct |
20 |
Correct |
4 ms |
18220 KB |
Output is correct |
21 |
Correct |
3 ms |
18084 KB |
Output is correct |
22 |
Correct |
3 ms |
18012 KB |
Output is correct |
23 |
Correct |
4 ms |
18012 KB |
Output is correct |
24 |
Correct |
4 ms |
18268 KB |
Output is correct |
25 |
Correct |
3 ms |
18140 KB |
Output is correct |
26 |
Correct |
4 ms |
18012 KB |
Output is correct |
27 |
Correct |
3 ms |
18136 KB |
Output is correct |
28 |
Correct |
3 ms |
18200 KB |
Output is correct |
29 |
Correct |
3 ms |
18008 KB |
Output is correct |
30 |
Correct |
4 ms |
18268 KB |
Output is correct |
31 |
Correct |
4 ms |
18284 KB |
Output is correct |
32 |
Correct |
3 ms |
18012 KB |
Output is correct |
33 |
Correct |
3 ms |
18012 KB |
Output is correct |
34 |
Correct |
3 ms |
18012 KB |
Output is correct |
35 |
Correct |
3 ms |
18012 KB |
Output is correct |
36 |
Correct |
4 ms |
18280 KB |
Output is correct |
37 |
Correct |
4 ms |
18268 KB |
Output is correct |
38 |
Correct |
3 ms |
18080 KB |
Output is correct |
39 |
Correct |
3 ms |
18076 KB |
Output is correct |
40 |
Correct |
3 ms |
18012 KB |
Output is correct |
41 |
Correct |
3 ms |
18268 KB |
Output is correct |
42 |
Correct |
81 ms |
39948 KB |
Output is correct |
43 |
Correct |
74 ms |
38348 KB |
Output is correct |
44 |
Correct |
63 ms |
34868 KB |
Output is correct |
45 |
Correct |
95 ms |
72040 KB |
Output is correct |
46 |
Correct |
98 ms |
56856 KB |
Output is correct |
47 |
Correct |
84 ms |
48452 KB |
Output is correct |
48 |
Correct |
40 ms |
27468 KB |
Output is correct |
49 |
Correct |
77 ms |
41928 KB |
Output is correct |
50 |
Correct |
77 ms |
39616 KB |
Output is correct |
51 |
Correct |
93 ms |
71120 KB |
Output is correct |
52 |
Correct |
93 ms |
56392 KB |
Output is correct |
53 |
Correct |
88 ms |
45896 KB |
Output is correct |
54 |
Correct |
81 ms |
36288 KB |
Output is correct |
55 |
Correct |
39 ms |
32232 KB |
Output is correct |
56 |
Correct |
81 ms |
48580 KB |
Output is correct |
57 |
Correct |
102 ms |
74192 KB |
Output is correct |
58 |
Correct |
90 ms |
56404 KB |
Output is correct |
59 |
Correct |
102 ms |
48156 KB |
Output is correct |
60 |
Correct |
78 ms |
36288 KB |
Output is correct |
61 |
Correct |
74 ms |
38848 KB |
Output is correct |
62 |
Correct |
77 ms |
39616 KB |
Output is correct |
63 |
Correct |
97 ms |
74408 KB |
Output is correct |
64 |
Correct |
66 ms |
47980 KB |
Output is correct |
65 |
Correct |
87 ms |
46404 KB |
Output is correct |
66 |
Correct |
57 ms |
39900 KB |
Output is correct |
67 |
Correct |
68 ms |
36164 KB |
Output is correct |
68 |
Correct |
76 ms |
41028 KB |
Output is correct |
69 |
Correct |
97 ms |
74440 KB |
Output is correct |
70 |
Correct |
98 ms |
56720 KB |
Output is correct |
71 |
Correct |
91 ms |
44872 KB |
Output is correct |
72 |
Correct |
83 ms |
42436 KB |
Output is correct |
73 |
Correct |
72 ms |
37316 KB |
Output is correct |
74 |
Correct |
81 ms |
47680 KB |
Output is correct |
75 |
Correct |
92 ms |
46660 KB |
Output is correct |
76 |
Correct |
3 ms |
18012 KB |
Output is correct |
77 |
Correct |
4 ms |
18012 KB |
Output is correct |
78 |
Correct |
4 ms |
18008 KB |
Output is correct |
79 |
Correct |
4 ms |
18012 KB |
Output is correct |
80 |
Correct |
4 ms |
18012 KB |
Output is correct |
81 |
Correct |
4 ms |
18268 KB |
Output is correct |
82 |
Correct |
4 ms |
18268 KB |
Output is correct |
83 |
Correct |
4 ms |
18012 KB |
Output is correct |
84 |
Correct |
4 ms |
18012 KB |
Output is correct |
85 |
Correct |
3 ms |
18012 KB |
Output is correct |
86 |
Correct |
4 ms |
18012 KB |
Output is correct |
87 |
Correct |
3 ms |
18268 KB |
Output is correct |
88 |
Correct |
4 ms |
18012 KB |
Output is correct |
89 |
Correct |
3 ms |
18096 KB |
Output is correct |
90 |
Correct |
4 ms |
18108 KB |
Output is correct |
91 |
Correct |
4 ms |
18008 KB |
Output is correct |
92 |
Correct |
3 ms |
18028 KB |
Output is correct |
93 |
Correct |
3 ms |
18268 KB |
Output is correct |
94 |
Correct |
4 ms |
18264 KB |
Output is correct |
95 |
Correct |
3 ms |
18012 KB |
Output is correct |
96 |
Correct |
3 ms |
18008 KB |
Output is correct |
97 |
Correct |
3 ms |
18012 KB |
Output is correct |
98 |
Correct |
3 ms |
18012 KB |
Output is correct |
99 |
Correct |
3 ms |
18012 KB |
Output is correct |
100 |
Correct |
3 ms |
18292 KB |
Output is correct |
101 |
Correct |
3 ms |
18012 KB |
Output is correct |
102 |
Correct |
155 ms |
50756 KB |
Output is correct |
103 |
Correct |
151 ms |
45504 KB |
Output is correct |
104 |
Correct |
113 ms |
37564 KB |
Output is correct |
105 |
Correct |
102 ms |
37760 KB |
Output is correct |
106 |
Correct |
88 ms |
54280 KB |
Output is correct |
107 |
Correct |
87 ms |
46792 KB |
Output is correct |
108 |
Correct |
164 ms |
53956 KB |
Output is correct |
109 |
Correct |
59 ms |
30920 KB |
Output is correct |
110 |
Correct |
118 ms |
39876 KB |
Output is correct |
111 |
Correct |
156 ms |
37828 KB |
Output is correct |
112 |
Correct |
107 ms |
35792 KB |
Output is correct |
113 |
Correct |
87 ms |
46540 KB |
Output is correct |
114 |
Correct |
91 ms |
56328 KB |
Output is correct |
115 |
Correct |
67 ms |
32456 KB |
Output is correct |
116 |
Correct |
156 ms |
51392 KB |
Output is correct |
117 |
Correct |
114 ms |
40644 KB |
Output is correct |
118 |
Correct |
106 ms |
38340 KB |
Output is correct |
119 |
Correct |
110 ms |
34780 KB |
Output is correct |
120 |
Correct |
85 ms |
47384 KB |
Output is correct |
121 |
Correct |
83 ms |
46988 KB |
Output is correct |
122 |
Correct |
178 ms |
59744 KB |
Output is correct |
123 |
Correct |
167 ms |
50628 KB |
Output is correct |
124 |
Correct |
121 ms |
39460 KB |
Output is correct |
125 |
Correct |
119 ms |
39108 KB |
Output is correct |
126 |
Correct |
92 ms |
37448 KB |
Output is correct |
127 |
Correct |
51 ms |
33780 KB |
Output is correct |
128 |
Correct |
50 ms |
31948 KB |
Output is correct |
129 |
Correct |
186 ms |
58988 KB |
Output is correct |
130 |
Correct |
144 ms |
49860 KB |
Output is correct |
131 |
Correct |
126 ms |
44520 KB |
Output is correct |
132 |
Correct |
102 ms |
37436 KB |
Output is correct |
133 |
Correct |
101 ms |
37956 KB |
Output is correct |
134 |
Correct |
88 ms |
54280 KB |
Output is correct |
135 |
Correct |
82 ms |
49692 KB |
Output is correct |
136 |
Correct |
170 ms |
54088 KB |
Output is correct |
137 |
Correct |
170 ms |
58564 KB |
Output is correct |