#include <bits/stdc++.h>
using namespace std;
#define int long long
int n;
long long mon;
vector<pair<int,long long> > adj[300005];
long long off;
priority_queue<pair<long long,int> > pq;
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> mon;
long long org=mon;
for(int i=1; i<=n; i++){
long long a,b;
cin >> a >> b;
adj[b].push_back({i,a});
}
pq.push({mon,0});
while(!pq.empty()){
pair<long long,int> x=pq.top();
pq.pop();
x.first+=off;
if(x.first<0) continue;
if(x.first>mon){
off+=x.first-mon;
mon=x.first;
}
for(auto i:adj[x.second]){
pq.push({x.first+i.second-off,i.first});
}
}
cout << mon-org;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
16848 KB |
Output is correct |
2 |
Correct |
90 ms |
18120 KB |
Output is correct |
3 |
Correct |
90 ms |
18128 KB |
Output is correct |
4 |
Incorrect |
76 ms |
16088 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7256 KB |
Output is correct |
2 |
Correct |
1 ms |
7260 KB |
Output is correct |
3 |
Correct |
2 ms |
7260 KB |
Output is correct |
4 |
Correct |
2 ms |
7516 KB |
Output is correct |
5 |
Correct |
2 ms |
7516 KB |
Output is correct |
6 |
Correct |
2 ms |
7516 KB |
Output is correct |
7 |
Correct |
2 ms |
7516 KB |
Output is correct |
8 |
Correct |
2 ms |
7516 KB |
Output is correct |
9 |
Correct |
2 ms |
7516 KB |
Output is correct |
10 |
Correct |
2 ms |
7516 KB |
Output is correct |
11 |
Correct |
2 ms |
7332 KB |
Output is correct |
12 |
Correct |
2 ms |
7516 KB |
Output is correct |
13 |
Correct |
2 ms |
7516 KB |
Output is correct |
14 |
Correct |
2 ms |
7516 KB |
Output is correct |
15 |
Correct |
3 ms |
7512 KB |
Output is correct |
16 |
Correct |
2 ms |
7516 KB |
Output is correct |
17 |
Correct |
2 ms |
7516 KB |
Output is correct |
18 |
Correct |
2 ms |
7516 KB |
Output is correct |
19 |
Correct |
2 ms |
7516 KB |
Output is correct |
20 |
Correct |
2 ms |
7516 KB |
Output is correct |
21 |
Correct |
2 ms |
7516 KB |
Output is correct |
22 |
Correct |
2 ms |
7512 KB |
Output is correct |
23 |
Correct |
2 ms |
7516 KB |
Output is correct |
24 |
Correct |
2 ms |
7512 KB |
Output is correct |
25 |
Correct |
2 ms |
7512 KB |
Output is correct |
26 |
Correct |
2 ms |
7516 KB |
Output is correct |
27 |
Correct |
2 ms |
7512 KB |
Output is correct |
28 |
Correct |
2 ms |
7516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7256 KB |
Output is correct |
2 |
Correct |
1 ms |
7260 KB |
Output is correct |
3 |
Correct |
2 ms |
7260 KB |
Output is correct |
4 |
Correct |
2 ms |
7516 KB |
Output is correct |
5 |
Correct |
2 ms |
7516 KB |
Output is correct |
6 |
Correct |
2 ms |
7516 KB |
Output is correct |
7 |
Correct |
2 ms |
7516 KB |
Output is correct |
8 |
Correct |
2 ms |
7516 KB |
Output is correct |
9 |
Correct |
2 ms |
7516 KB |
Output is correct |
10 |
Correct |
2 ms |
7516 KB |
Output is correct |
11 |
Correct |
2 ms |
7332 KB |
Output is correct |
12 |
Correct |
2 ms |
7516 KB |
Output is correct |
13 |
Correct |
2 ms |
7516 KB |
Output is correct |
14 |
Correct |
2 ms |
7516 KB |
Output is correct |
15 |
Correct |
3 ms |
7512 KB |
Output is correct |
16 |
Correct |
2 ms |
7516 KB |
Output is correct |
17 |
Correct |
2 ms |
7516 KB |
Output is correct |
18 |
Correct |
2 ms |
7516 KB |
Output is correct |
19 |
Correct |
2 ms |
7516 KB |
Output is correct |
20 |
Correct |
2 ms |
7516 KB |
Output is correct |
21 |
Correct |
2 ms |
7516 KB |
Output is correct |
22 |
Correct |
2 ms |
7512 KB |
Output is correct |
23 |
Correct |
2 ms |
7516 KB |
Output is correct |
24 |
Correct |
2 ms |
7512 KB |
Output is correct |
25 |
Correct |
2 ms |
7512 KB |
Output is correct |
26 |
Correct |
2 ms |
7516 KB |
Output is correct |
27 |
Correct |
2 ms |
7512 KB |
Output is correct |
28 |
Correct |
2 ms |
7516 KB |
Output is correct |
29 |
Correct |
71 ms |
16720 KB |
Output is correct |
30 |
Correct |
79 ms |
17020 KB |
Output is correct |
31 |
Correct |
79 ms |
22456 KB |
Output is correct |
32 |
Correct |
49 ms |
16720 KB |
Output is correct |
33 |
Correct |
46 ms |
16720 KB |
Output is correct |
34 |
Correct |
47 ms |
16756 KB |
Output is correct |
35 |
Correct |
27 ms |
12112 KB |
Output is correct |
36 |
Correct |
86 ms |
17348 KB |
Output is correct |
37 |
Correct |
74 ms |
16976 KB |
Output is correct |
38 |
Correct |
56 ms |
16720 KB |
Output is correct |
39 |
Correct |
50 ms |
16808 KB |
Output is correct |
40 |
Correct |
59 ms |
16548 KB |
Output is correct |
41 |
Correct |
50 ms |
16720 KB |
Output is correct |
42 |
Correct |
30 ms |
12244 KB |
Output is correct |
43 |
Correct |
63 ms |
16992 KB |
Output is correct |
44 |
Correct |
49 ms |
16464 KB |
Output is correct |
45 |
Correct |
46 ms |
16836 KB |
Output is correct |
46 |
Correct |
51 ms |
16724 KB |
Output is correct |
47 |
Correct |
58 ms |
16720 KB |
Output is correct |
48 |
Correct |
81 ms |
18312 KB |
Output is correct |
49 |
Correct |
74 ms |
16724 KB |
Output is correct |
50 |
Correct |
52 ms |
16596 KB |
Output is correct |
51 |
Correct |
35 ms |
13648 KB |
Output is correct |
52 |
Correct |
44 ms |
16732 KB |
Output is correct |
53 |
Correct |
36 ms |
13736 KB |
Output is correct |
54 |
Correct |
78 ms |
18312 KB |
Output is correct |
55 |
Correct |
76 ms |
16868 KB |
Output is correct |
56 |
Correct |
49 ms |
16468 KB |
Output is correct |
57 |
Correct |
50 ms |
16720 KB |
Output is correct |
58 |
Correct |
44 ms |
16732 KB |
Output is correct |
59 |
Correct |
54 ms |
16832 KB |
Output is correct |
60 |
Correct |
59 ms |
18372 KB |
Output is correct |
61 |
Correct |
64 ms |
16976 KB |
Output is correct |
62 |
Correct |
55 ms |
16720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7256 KB |
Output is correct |
2 |
Correct |
1 ms |
7260 KB |
Output is correct |
3 |
Correct |
2 ms |
7260 KB |
Output is correct |
4 |
Correct |
2 ms |
7516 KB |
Output is correct |
5 |
Correct |
2 ms |
7516 KB |
Output is correct |
6 |
Correct |
2 ms |
7516 KB |
Output is correct |
7 |
Correct |
2 ms |
7516 KB |
Output is correct |
8 |
Correct |
2 ms |
7516 KB |
Output is correct |
9 |
Correct |
2 ms |
7516 KB |
Output is correct |
10 |
Correct |
2 ms |
7516 KB |
Output is correct |
11 |
Correct |
2 ms |
7332 KB |
Output is correct |
12 |
Correct |
2 ms |
7516 KB |
Output is correct |
13 |
Correct |
2 ms |
7516 KB |
Output is correct |
14 |
Correct |
2 ms |
7516 KB |
Output is correct |
15 |
Correct |
3 ms |
7512 KB |
Output is correct |
16 |
Correct |
2 ms |
7516 KB |
Output is correct |
17 |
Correct |
2 ms |
7516 KB |
Output is correct |
18 |
Correct |
2 ms |
7516 KB |
Output is correct |
19 |
Correct |
2 ms |
7516 KB |
Output is correct |
20 |
Correct |
2 ms |
7516 KB |
Output is correct |
21 |
Correct |
2 ms |
7516 KB |
Output is correct |
22 |
Correct |
2 ms |
7512 KB |
Output is correct |
23 |
Correct |
2 ms |
7516 KB |
Output is correct |
24 |
Correct |
2 ms |
7512 KB |
Output is correct |
25 |
Correct |
2 ms |
7512 KB |
Output is correct |
26 |
Correct |
2 ms |
7516 KB |
Output is correct |
27 |
Correct |
2 ms |
7512 KB |
Output is correct |
28 |
Correct |
2 ms |
7516 KB |
Output is correct |
29 |
Correct |
2 ms |
7260 KB |
Output is correct |
30 |
Correct |
2 ms |
7512 KB |
Output is correct |
31 |
Correct |
2 ms |
7516 KB |
Output is correct |
32 |
Correct |
2 ms |
7532 KB |
Output is correct |
33 |
Incorrect |
2 ms |
7516 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
16848 KB |
Output is correct |
2 |
Correct |
90 ms |
18120 KB |
Output is correct |
3 |
Correct |
90 ms |
18128 KB |
Output is correct |
4 |
Incorrect |
76 ms |
16088 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |