#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
priority_queue<ll> pq;
ll ans = 0, pref = 0, x, y;
for(int i = 0; i < n; i++){
pq.push(0);
}
for(int i = 0; i < n - 1; i++){
cin >> x >> y;
pref += (x - y);
pq.push(pref);
if(pref < pq.top()){
ans += pq.top() - pref;
pq.pop(); pq.push(pref);
}
}
cin >> x >> y;
pref += (x - y);
while(pq.size() && pref < pq.top()){
ans += pq.top() - pref;
pq.pop();
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
16 ms |
1620 KB |
Output is correct |
5 |
Correct |
30 ms |
2768 KB |
Output is correct |
6 |
Correct |
95 ms |
7608 KB |
Output is correct |
7 |
Correct |
151 ms |
14940 KB |
Output is correct |
8 |
Correct |
137 ms |
13148 KB |
Output is correct |
9 |
Correct |
124 ms |
12384 KB |
Output is correct |
10 |
Correct |
95 ms |
10152 KB |
Output is correct |
11 |
Correct |
100 ms |
10188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
16 ms |
1620 KB |
Output is correct |
5 |
Correct |
30 ms |
2768 KB |
Output is correct |
6 |
Correct |
95 ms |
7608 KB |
Output is correct |
7 |
Correct |
151 ms |
14940 KB |
Output is correct |
8 |
Correct |
137 ms |
13148 KB |
Output is correct |
9 |
Correct |
124 ms |
12384 KB |
Output is correct |
10 |
Correct |
95 ms |
10152 KB |
Output is correct |
11 |
Correct |
100 ms |
10188 KB |
Output is correct |
12 |
Correct |
45 ms |
4008 KB |
Output is correct |
13 |
Correct |
115 ms |
11816 KB |
Output is correct |
14 |
Correct |
134 ms |
14960 KB |
Output is correct |
15 |
Correct |
137 ms |
13056 KB |
Output is correct |
16 |
Correct |
181 ms |
12436 KB |
Output is correct |
17 |
Correct |
75 ms |
10168 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
408 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
16 ms |
1620 KB |
Output is correct |
12 |
Correct |
30 ms |
2768 KB |
Output is correct |
13 |
Correct |
95 ms |
7608 KB |
Output is correct |
14 |
Correct |
151 ms |
14940 KB |
Output is correct |
15 |
Correct |
137 ms |
13148 KB |
Output is correct |
16 |
Correct |
124 ms |
12384 KB |
Output is correct |
17 |
Correct |
95 ms |
10152 KB |
Output is correct |
18 |
Correct |
100 ms |
10188 KB |
Output is correct |
19 |
Correct |
45 ms |
4008 KB |
Output is correct |
20 |
Correct |
115 ms |
11816 KB |
Output is correct |
21 |
Correct |
134 ms |
14960 KB |
Output is correct |
22 |
Correct |
137 ms |
13056 KB |
Output is correct |
23 |
Correct |
181 ms |
12436 KB |
Output is correct |
24 |
Correct |
75 ms |
10168 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
408 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
34 ms |
4104 KB |
Output is correct |
34 |
Correct |
89 ms |
11812 KB |
Output is correct |
35 |
Correct |
148 ms |
14972 KB |
Output is correct |
36 |
Correct |
145 ms |
12516 KB |
Output is correct |
37 |
Correct |
119 ms |
13100 KB |
Output is correct |
38 |
Correct |
136 ms |
14952 KB |
Output is correct |
39 |
Correct |
93 ms |
11108 KB |
Output is correct |
40 |
Correct |
92 ms |
10380 KB |
Output is correct |
41 |
Correct |
85 ms |
10100 KB |
Output is correct |
42 |
Correct |
88 ms |
10144 KB |
Output is correct |
43 |
Correct |
86 ms |
10156 KB |
Output is correct |
44 |
Correct |
87 ms |
10208 KB |
Output is correct |
45 |
Correct |
162 ms |
14908 KB |
Output is correct |
46 |
Correct |
75 ms |
10536 KB |
Output is correct |
47 |
Correct |
90 ms |
9784 KB |
Output is correct |