# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
994752 |
2024-06-08T04:54:37 Z |
kym |
Jobs (BOI24_jobs) |
C++14 |
|
193 ms |
72900 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#ifdef LOCAL
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
const int MAXN = 300005;
const int inf=1000000500ll;
const long long oo =1000000000000000500ll;
const int MOD = (int)1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> pi;
int n,init;
int A[MAXN], P[MAXN];
vector<int>child[MAXN];
priority_queue<pi,vector<pi>,greater<pi>> * dfs(int x){
priority_queue<pi,vector<pi>,greater<pi>> * pq = new priority_queue<pi,vector<pi>,greater<pi>>();
for(auto v:child[x]){
priority_queue<pi,vector<pi>,greater<pi>> * c = dfs(v);
if(c->size() > pq->size())swap(c,pq);
while(c->size()){
pq->push(c->top());c->pop();
}
}
if(A[x]>=0){
pq->push({0,A[x]});
} else{
int s = A[x];
int lim = -A[x];
while(s<0 && pq->size()){
lim = max(lim, pq->top().first - s);// you actually need this amount of initial capital now.
s+=pq->top().second;
pq->pop();
}
int sum=0;
while(pq->size() && pq->top().first < lim){
sum += pq->top().second;
pq->pop();
}
if(sum){
pq->push({lim,sum});
}
if(s>0)pq->push({lim,s});
}
return pq;
}
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> init;
for(int i=1;i<=n;i++){
cin>>A[i]>>P[i];
child[P[i]].push_back(i);
}
priority_queue<pi,vector<pi>,greater<pi>> * pq =dfs(0);
int ans=0;
while(pq->size() && pq->top().first<=init){
ans += pq->top().second;
init += pq->top().second;
pq->pop();
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
164 ms |
56220 KB |
Output is correct |
2 |
Correct |
122 ms |
45472 KB |
Output is correct |
3 |
Correct |
98 ms |
40948 KB |
Output is correct |
4 |
Correct |
104 ms |
48316 KB |
Output is correct |
5 |
Correct |
92 ms |
56004 KB |
Output is correct |
6 |
Correct |
87 ms |
38092 KB |
Output is correct |
7 |
Correct |
140 ms |
51280 KB |
Output is correct |
8 |
Correct |
107 ms |
40012 KB |
Output is correct |
9 |
Correct |
89 ms |
51180 KB |
Output is correct |
10 |
Correct |
88 ms |
55956 KB |
Output is correct |
11 |
Correct |
176 ms |
58048 KB |
Output is correct |
12 |
Correct |
154 ms |
47300 KB |
Output is correct |
13 |
Correct |
157 ms |
54668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Correct |
2 ms |
10844 KB |
Output is correct |
3 |
Correct |
2 ms |
10844 KB |
Output is correct |
4 |
Correct |
2 ms |
10844 KB |
Output is correct |
5 |
Correct |
2 ms |
11100 KB |
Output is correct |
6 |
Correct |
2 ms |
11112 KB |
Output is correct |
7 |
Correct |
2 ms |
11100 KB |
Output is correct |
8 |
Correct |
2 ms |
10844 KB |
Output is correct |
9 |
Correct |
2 ms |
10844 KB |
Output is correct |
10 |
Correct |
2 ms |
10844 KB |
Output is correct |
11 |
Correct |
2 ms |
11100 KB |
Output is correct |
12 |
Correct |
2 ms |
11172 KB |
Output is correct |
13 |
Correct |
3 ms |
11100 KB |
Output is correct |
14 |
Correct |
3 ms |
11100 KB |
Output is correct |
15 |
Correct |
2 ms |
10844 KB |
Output is correct |
16 |
Correct |
2 ms |
10844 KB |
Output is correct |
17 |
Correct |
2 ms |
11100 KB |
Output is correct |
18 |
Correct |
2 ms |
11100 KB |
Output is correct |
19 |
Correct |
2 ms |
11100 KB |
Output is correct |
20 |
Correct |
3 ms |
10856 KB |
Output is correct |
21 |
Correct |
3 ms |
10844 KB |
Output is correct |
22 |
Correct |
2 ms |
10844 KB |
Output is correct |
23 |
Correct |
2 ms |
11100 KB |
Output is correct |
24 |
Correct |
2 ms |
11100 KB |
Output is correct |
25 |
Correct |
3 ms |
11100 KB |
Output is correct |
26 |
Correct |
3 ms |
11100 KB |
Output is correct |
27 |
Correct |
2 ms |
10840 KB |
Output is correct |
28 |
Correct |
3 ms |
11096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Correct |
2 ms |
10844 KB |
Output is correct |
3 |
Correct |
2 ms |
10844 KB |
Output is correct |
4 |
Correct |
2 ms |
10844 KB |
Output is correct |
5 |
Correct |
2 ms |
11100 KB |
Output is correct |
6 |
Correct |
2 ms |
11112 KB |
Output is correct |
7 |
Correct |
2 ms |
11100 KB |
Output is correct |
8 |
Correct |
2 ms |
10844 KB |
Output is correct |
9 |
Correct |
2 ms |
10844 KB |
Output is correct |
10 |
Correct |
2 ms |
10844 KB |
Output is correct |
11 |
Correct |
2 ms |
11100 KB |
Output is correct |
12 |
Correct |
2 ms |
11172 KB |
Output is correct |
13 |
Correct |
3 ms |
11100 KB |
Output is correct |
14 |
Correct |
3 ms |
11100 KB |
Output is correct |
15 |
Correct |
2 ms |
10844 KB |
Output is correct |
16 |
Correct |
2 ms |
10844 KB |
Output is correct |
17 |
Correct |
2 ms |
11100 KB |
Output is correct |
18 |
Correct |
2 ms |
11100 KB |
Output is correct |
19 |
Correct |
2 ms |
11100 KB |
Output is correct |
20 |
Correct |
3 ms |
10856 KB |
Output is correct |
21 |
Correct |
3 ms |
10844 KB |
Output is correct |
22 |
Correct |
2 ms |
10844 KB |
Output is correct |
23 |
Correct |
2 ms |
11100 KB |
Output is correct |
24 |
Correct |
2 ms |
11100 KB |
Output is correct |
25 |
Correct |
3 ms |
11100 KB |
Output is correct |
26 |
Correct |
3 ms |
11100 KB |
Output is correct |
27 |
Correct |
2 ms |
10840 KB |
Output is correct |
28 |
Correct |
3 ms |
11096 KB |
Output is correct |
29 |
Correct |
88 ms |
40900 KB |
Output is correct |
30 |
Correct |
85 ms |
41316 KB |
Output is correct |
31 |
Correct |
77 ms |
40120 KB |
Output is correct |
32 |
Correct |
137 ms |
71528 KB |
Output is correct |
33 |
Correct |
98 ms |
57936 KB |
Output is correct |
34 |
Correct |
90 ms |
50896 KB |
Output is correct |
35 |
Correct |
49 ms |
25164 KB |
Output is correct |
36 |
Correct |
102 ms |
44996 KB |
Output is correct |
37 |
Correct |
95 ms |
42536 KB |
Output is correct |
38 |
Correct |
103 ms |
70456 KB |
Output is correct |
39 |
Correct |
106 ms |
57956 KB |
Output is correct |
40 |
Correct |
105 ms |
48752 KB |
Output is correct |
41 |
Correct |
85 ms |
40364 KB |
Output is correct |
42 |
Correct |
40 ms |
29600 KB |
Output is correct |
43 |
Correct |
109 ms |
50784 KB |
Output is correct |
44 |
Correct |
112 ms |
72508 KB |
Output is correct |
45 |
Correct |
105 ms |
57740 KB |
Output is correct |
46 |
Correct |
124 ms |
50660 KB |
Output is correct |
47 |
Correct |
108 ms |
40332 KB |
Output is correct |
48 |
Correct |
92 ms |
40700 KB |
Output is correct |
49 |
Correct |
103 ms |
41048 KB |
Output is correct |
50 |
Correct |
106 ms |
71908 KB |
Output is correct |
51 |
Correct |
68 ms |
45256 KB |
Output is correct |
52 |
Correct |
103 ms |
48200 KB |
Output is correct |
53 |
Correct |
68 ms |
38028 KB |
Output is correct |
54 |
Correct |
88 ms |
39620 KB |
Output is correct |
55 |
Correct |
101 ms |
42552 KB |
Output is correct |
56 |
Correct |
111 ms |
72900 KB |
Output is correct |
57 |
Correct |
120 ms |
59212 KB |
Output is correct |
58 |
Correct |
104 ms |
48572 KB |
Output is correct |
59 |
Correct |
97 ms |
45576 KB |
Output is correct |
60 |
Correct |
72 ms |
39876 KB |
Output is correct |
61 |
Correct |
104 ms |
50384 KB |
Output is correct |
62 |
Correct |
113 ms |
50328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Correct |
2 ms |
10844 KB |
Output is correct |
3 |
Correct |
2 ms |
10844 KB |
Output is correct |
4 |
Correct |
2 ms |
10844 KB |
Output is correct |
5 |
Correct |
2 ms |
11100 KB |
Output is correct |
6 |
Correct |
2 ms |
11112 KB |
Output is correct |
7 |
Correct |
2 ms |
11100 KB |
Output is correct |
8 |
Correct |
2 ms |
10844 KB |
Output is correct |
9 |
Correct |
2 ms |
10844 KB |
Output is correct |
10 |
Correct |
2 ms |
10844 KB |
Output is correct |
11 |
Correct |
2 ms |
11100 KB |
Output is correct |
12 |
Correct |
2 ms |
11172 KB |
Output is correct |
13 |
Correct |
3 ms |
11100 KB |
Output is correct |
14 |
Correct |
3 ms |
11100 KB |
Output is correct |
15 |
Correct |
2 ms |
10844 KB |
Output is correct |
16 |
Correct |
2 ms |
10844 KB |
Output is correct |
17 |
Correct |
2 ms |
11100 KB |
Output is correct |
18 |
Correct |
2 ms |
11100 KB |
Output is correct |
19 |
Correct |
2 ms |
11100 KB |
Output is correct |
20 |
Correct |
3 ms |
10856 KB |
Output is correct |
21 |
Correct |
3 ms |
10844 KB |
Output is correct |
22 |
Correct |
2 ms |
10844 KB |
Output is correct |
23 |
Correct |
2 ms |
11100 KB |
Output is correct |
24 |
Correct |
2 ms |
11100 KB |
Output is correct |
25 |
Correct |
3 ms |
11100 KB |
Output is correct |
26 |
Correct |
3 ms |
11100 KB |
Output is correct |
27 |
Correct |
2 ms |
10840 KB |
Output is correct |
28 |
Correct |
3 ms |
11096 KB |
Output is correct |
29 |
Correct |
2 ms |
10844 KB |
Output is correct |
30 |
Correct |
3 ms |
11100 KB |
Output is correct |
31 |
Correct |
3 ms |
11100 KB |
Output is correct |
32 |
Correct |
2 ms |
11100 KB |
Output is correct |
33 |
Correct |
2 ms |
11088 KB |
Output is correct |
34 |
Correct |
2 ms |
11096 KB |
Output is correct |
35 |
Correct |
2 ms |
11100 KB |
Output is correct |
36 |
Correct |
2 ms |
11100 KB |
Output is correct |
37 |
Correct |
2 ms |
11100 KB |
Output is correct |
38 |
Correct |
2 ms |
11096 KB |
Output is correct |
39 |
Correct |
2 ms |
10844 KB |
Output is correct |
40 |
Correct |
4 ms |
11100 KB |
Output is correct |
41 |
Correct |
2 ms |
11100 KB |
Output is correct |
42 |
Correct |
2 ms |
11096 KB |
Output is correct |
43 |
Correct |
2 ms |
11100 KB |
Output is correct |
44 |
Correct |
3 ms |
11100 KB |
Output is correct |
45 |
Correct |
3 ms |
10840 KB |
Output is correct |
46 |
Correct |
2 ms |
11100 KB |
Output is correct |
47 |
Correct |
2 ms |
11100 KB |
Output is correct |
48 |
Correct |
2 ms |
11100 KB |
Output is correct |
49 |
Correct |
2 ms |
11100 KB |
Output is correct |
50 |
Correct |
2 ms |
11100 KB |
Output is correct |
51 |
Correct |
2 ms |
10844 KB |
Output is correct |
52 |
Correct |
2 ms |
11100 KB |
Output is correct |
53 |
Correct |
2 ms |
11100 KB |
Output is correct |
54 |
Correct |
2 ms |
11100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
164 ms |
56220 KB |
Output is correct |
2 |
Correct |
122 ms |
45472 KB |
Output is correct |
3 |
Correct |
98 ms |
40948 KB |
Output is correct |
4 |
Correct |
104 ms |
48316 KB |
Output is correct |
5 |
Correct |
92 ms |
56004 KB |
Output is correct |
6 |
Correct |
87 ms |
38092 KB |
Output is correct |
7 |
Correct |
140 ms |
51280 KB |
Output is correct |
8 |
Correct |
107 ms |
40012 KB |
Output is correct |
9 |
Correct |
89 ms |
51180 KB |
Output is correct |
10 |
Correct |
88 ms |
55956 KB |
Output is correct |
11 |
Correct |
176 ms |
58048 KB |
Output is correct |
12 |
Correct |
154 ms |
47300 KB |
Output is correct |
13 |
Correct |
157 ms |
54668 KB |
Output is correct |
14 |
Correct |
2 ms |
10844 KB |
Output is correct |
15 |
Correct |
2 ms |
10844 KB |
Output is correct |
16 |
Correct |
2 ms |
10844 KB |
Output is correct |
17 |
Correct |
2 ms |
10844 KB |
Output is correct |
18 |
Correct |
2 ms |
11100 KB |
Output is correct |
19 |
Correct |
2 ms |
11112 KB |
Output is correct |
20 |
Correct |
2 ms |
11100 KB |
Output is correct |
21 |
Correct |
2 ms |
10844 KB |
Output is correct |
22 |
Correct |
2 ms |
10844 KB |
Output is correct |
23 |
Correct |
2 ms |
10844 KB |
Output is correct |
24 |
Correct |
2 ms |
11100 KB |
Output is correct |
25 |
Correct |
2 ms |
11172 KB |
Output is correct |
26 |
Correct |
3 ms |
11100 KB |
Output is correct |
27 |
Correct |
3 ms |
11100 KB |
Output is correct |
28 |
Correct |
2 ms |
10844 KB |
Output is correct |
29 |
Correct |
2 ms |
10844 KB |
Output is correct |
30 |
Correct |
2 ms |
11100 KB |
Output is correct |
31 |
Correct |
2 ms |
11100 KB |
Output is correct |
32 |
Correct |
2 ms |
11100 KB |
Output is correct |
33 |
Correct |
3 ms |
10856 KB |
Output is correct |
34 |
Correct |
3 ms |
10844 KB |
Output is correct |
35 |
Correct |
2 ms |
10844 KB |
Output is correct |
36 |
Correct |
2 ms |
11100 KB |
Output is correct |
37 |
Correct |
2 ms |
11100 KB |
Output is correct |
38 |
Correct |
3 ms |
11100 KB |
Output is correct |
39 |
Correct |
3 ms |
11100 KB |
Output is correct |
40 |
Correct |
2 ms |
10840 KB |
Output is correct |
41 |
Correct |
3 ms |
11096 KB |
Output is correct |
42 |
Correct |
88 ms |
40900 KB |
Output is correct |
43 |
Correct |
85 ms |
41316 KB |
Output is correct |
44 |
Correct |
77 ms |
40120 KB |
Output is correct |
45 |
Correct |
137 ms |
71528 KB |
Output is correct |
46 |
Correct |
98 ms |
57936 KB |
Output is correct |
47 |
Correct |
90 ms |
50896 KB |
Output is correct |
48 |
Correct |
49 ms |
25164 KB |
Output is correct |
49 |
Correct |
102 ms |
44996 KB |
Output is correct |
50 |
Correct |
95 ms |
42536 KB |
Output is correct |
51 |
Correct |
103 ms |
70456 KB |
Output is correct |
52 |
Correct |
106 ms |
57956 KB |
Output is correct |
53 |
Correct |
105 ms |
48752 KB |
Output is correct |
54 |
Correct |
85 ms |
40364 KB |
Output is correct |
55 |
Correct |
40 ms |
29600 KB |
Output is correct |
56 |
Correct |
109 ms |
50784 KB |
Output is correct |
57 |
Correct |
112 ms |
72508 KB |
Output is correct |
58 |
Correct |
105 ms |
57740 KB |
Output is correct |
59 |
Correct |
124 ms |
50660 KB |
Output is correct |
60 |
Correct |
108 ms |
40332 KB |
Output is correct |
61 |
Correct |
92 ms |
40700 KB |
Output is correct |
62 |
Correct |
103 ms |
41048 KB |
Output is correct |
63 |
Correct |
106 ms |
71908 KB |
Output is correct |
64 |
Correct |
68 ms |
45256 KB |
Output is correct |
65 |
Correct |
103 ms |
48200 KB |
Output is correct |
66 |
Correct |
68 ms |
38028 KB |
Output is correct |
67 |
Correct |
88 ms |
39620 KB |
Output is correct |
68 |
Correct |
101 ms |
42552 KB |
Output is correct |
69 |
Correct |
111 ms |
72900 KB |
Output is correct |
70 |
Correct |
120 ms |
59212 KB |
Output is correct |
71 |
Correct |
104 ms |
48572 KB |
Output is correct |
72 |
Correct |
97 ms |
45576 KB |
Output is correct |
73 |
Correct |
72 ms |
39876 KB |
Output is correct |
74 |
Correct |
104 ms |
50384 KB |
Output is correct |
75 |
Correct |
113 ms |
50328 KB |
Output is correct |
76 |
Correct |
2 ms |
10844 KB |
Output is correct |
77 |
Correct |
3 ms |
11100 KB |
Output is correct |
78 |
Correct |
3 ms |
11100 KB |
Output is correct |
79 |
Correct |
2 ms |
11100 KB |
Output is correct |
80 |
Correct |
2 ms |
11088 KB |
Output is correct |
81 |
Correct |
2 ms |
11096 KB |
Output is correct |
82 |
Correct |
2 ms |
11100 KB |
Output is correct |
83 |
Correct |
2 ms |
11100 KB |
Output is correct |
84 |
Correct |
2 ms |
11100 KB |
Output is correct |
85 |
Correct |
2 ms |
11096 KB |
Output is correct |
86 |
Correct |
2 ms |
10844 KB |
Output is correct |
87 |
Correct |
4 ms |
11100 KB |
Output is correct |
88 |
Correct |
2 ms |
11100 KB |
Output is correct |
89 |
Correct |
2 ms |
11096 KB |
Output is correct |
90 |
Correct |
2 ms |
11100 KB |
Output is correct |
91 |
Correct |
3 ms |
11100 KB |
Output is correct |
92 |
Correct |
3 ms |
10840 KB |
Output is correct |
93 |
Correct |
2 ms |
11100 KB |
Output is correct |
94 |
Correct |
2 ms |
11100 KB |
Output is correct |
95 |
Correct |
2 ms |
11100 KB |
Output is correct |
96 |
Correct |
2 ms |
11100 KB |
Output is correct |
97 |
Correct |
2 ms |
11100 KB |
Output is correct |
98 |
Correct |
2 ms |
10844 KB |
Output is correct |
99 |
Correct |
2 ms |
11100 KB |
Output is correct |
100 |
Correct |
2 ms |
11100 KB |
Output is correct |
101 |
Correct |
2 ms |
11100 KB |
Output is correct |
102 |
Correct |
142 ms |
55648 KB |
Output is correct |
103 |
Correct |
135 ms |
48832 KB |
Output is correct |
104 |
Correct |
107 ms |
41980 KB |
Output is correct |
105 |
Correct |
81 ms |
40228 KB |
Output is correct |
106 |
Correct |
90 ms |
56516 KB |
Output is correct |
107 |
Correct |
90 ms |
49092 KB |
Output is correct |
108 |
Correct |
168 ms |
56964 KB |
Output is correct |
109 |
Correct |
67 ms |
28640 KB |
Output is correct |
110 |
Correct |
107 ms |
44180 KB |
Output is correct |
111 |
Correct |
109 ms |
42696 KB |
Output is correct |
112 |
Correct |
100 ms |
39616 KB |
Output is correct |
113 |
Correct |
94 ms |
48836 KB |
Output is correct |
114 |
Correct |
106 ms |
57028 KB |
Output is correct |
115 |
Correct |
63 ms |
30152 KB |
Output is correct |
116 |
Correct |
161 ms |
54656 KB |
Output is correct |
117 |
Correct |
119 ms |
45248 KB |
Output is correct |
118 |
Correct |
117 ms |
42268 KB |
Output is correct |
119 |
Correct |
90 ms |
39216 KB |
Output is correct |
120 |
Correct |
94 ms |
48320 KB |
Output is correct |
121 |
Correct |
90 ms |
48576 KB |
Output is correct |
122 |
Correct |
193 ms |
61668 KB |
Output is correct |
123 |
Correct |
154 ms |
54208 KB |
Output is correct |
124 |
Correct |
114 ms |
43968 KB |
Output is correct |
125 |
Correct |
131 ms |
42940 KB |
Output is correct |
126 |
Correct |
100 ms |
39956 KB |
Output is correct |
127 |
Correct |
56 ms |
31860 KB |
Output is correct |
128 |
Correct |
48 ms |
28396 KB |
Output is correct |
129 |
Correct |
171 ms |
63680 KB |
Output is correct |
130 |
Correct |
149 ms |
54640 KB |
Output is correct |
131 |
Correct |
118 ms |
46528 KB |
Output is correct |
132 |
Correct |
110 ms |
42304 KB |
Output is correct |
133 |
Correct |
100 ms |
39668 KB |
Output is correct |
134 |
Correct |
93 ms |
57540 KB |
Output is correct |
135 |
Correct |
84 ms |
51904 KB |
Output is correct |
136 |
Correct |
177 ms |
58980 KB |
Output is correct |
137 |
Correct |
176 ms |
60096 KB |
Output is correct |