#include <bits/stdc++.h>
using namespace std;
long long int c[500'009];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n,a,b,odp = 0;
cin >> n;
c[0] = 0;
for (int x=1;x<=n;x++){
cin >> a >> b;
c[x] = a-b;
//c[x] -= x;
c[x] += c[x-1];
}
priority_queue<int> slope;
slope.push(0);
for (int x=1;x<=n;x++){
if (c[x] < 0){
odp += 0 - c[x];
c[x] = 0;
}
if (c[x] > c[n]){
odp += c[x] - c[n];
c[x] = c[n];
}
slope.push(c[x]);
if (c[x] < slope.top()){
odp += slope.top() - c[x];
slope.pop();
slope.push(c[x]);
}
}
cout << odp << "\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 |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
7 ms |
1080 KB |
Output is correct |
5 |
Correct |
13 ms |
2304 KB |
Output is correct |
6 |
Correct |
49 ms |
6772 KB |
Output is correct |
7 |
Correct |
81 ms |
13072 KB |
Output is correct |
8 |
Correct |
67 ms |
11276 KB |
Output is correct |
9 |
Correct |
64 ms |
10560 KB |
Output is correct |
10 |
Correct |
48 ms |
8316 KB |
Output is correct |
11 |
Correct |
59 ms |
8384 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 |
7 ms |
1080 KB |
Output is correct |
5 |
Correct |
13 ms |
2304 KB |
Output is correct |
6 |
Correct |
49 ms |
6772 KB |
Output is correct |
7 |
Correct |
81 ms |
13072 KB |
Output is correct |
8 |
Correct |
67 ms |
11276 KB |
Output is correct |
9 |
Correct |
64 ms |
10560 KB |
Output is correct |
10 |
Correct |
48 ms |
8316 KB |
Output is correct |
11 |
Correct |
59 ms |
8384 KB |
Output is correct |
12 |
Correct |
21 ms |
3628 KB |
Output is correct |
13 |
Correct |
53 ms |
8856 KB |
Output is correct |
14 |
Correct |
84 ms |
13156 KB |
Output is correct |
15 |
Correct |
68 ms |
11376 KB |
Output is correct |
16 |
Correct |
67 ms |
10548 KB |
Output is correct |
17 |
Correct |
62 ms |
8264 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 |
0 ms |
256 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 |
340 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 |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
256 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 |
340 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 |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
368 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 |
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 |
0 ms |
256 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 |
340 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 |
7 ms |
1080 KB |
Output is correct |
12 |
Correct |
13 ms |
2304 KB |
Output is correct |
13 |
Correct |
49 ms |
6772 KB |
Output is correct |
14 |
Correct |
81 ms |
13072 KB |
Output is correct |
15 |
Correct |
67 ms |
11276 KB |
Output is correct |
16 |
Correct |
64 ms |
10560 KB |
Output is correct |
17 |
Correct |
48 ms |
8316 KB |
Output is correct |
18 |
Correct |
59 ms |
8384 KB |
Output is correct |
19 |
Correct |
21 ms |
3628 KB |
Output is correct |
20 |
Correct |
53 ms |
8856 KB |
Output is correct |
21 |
Correct |
84 ms |
13156 KB |
Output is correct |
22 |
Correct |
68 ms |
11376 KB |
Output is correct |
23 |
Correct |
67 ms |
10548 KB |
Output is correct |
24 |
Correct |
62 ms |
8264 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
368 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 |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
33 ms |
3636 KB |
Output is correct |
34 |
Correct |
78 ms |
8860 KB |
Output is correct |
35 |
Correct |
132 ms |
13084 KB |
Output is correct |
36 |
Correct |
125 ms |
10768 KB |
Output is correct |
37 |
Correct |
65 ms |
11196 KB |
Output is correct |
38 |
Correct |
119 ms |
13192 KB |
Output is correct |
39 |
Correct |
68 ms |
9276 KB |
Output is correct |
40 |
Correct |
76 ms |
8852 KB |
Output is correct |
41 |
Correct |
72 ms |
8384 KB |
Output is correct |
42 |
Correct |
66 ms |
8264 KB |
Output is correct |
43 |
Correct |
69 ms |
8316 KB |
Output is correct |
44 |
Correct |
69 ms |
8316 KB |
Output is correct |
45 |
Correct |
96 ms |
13128 KB |
Output is correct |
46 |
Correct |
65 ms |
8576 KB |
Output is correct |
47 |
Correct |
82 ms |
8232 KB |
Output is correct |