#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef complex<ld> cp;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<cp> vcp;
typedef vector<ld> vld;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vii> vvii;
#define fastIO ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define forw(i,l,r) for( int i = (l) ; i < (r) ; i++ )
#define forb(i,r,l) for( int i = (r) ; i >= (l) ; i-- )
#define log2i(x) (32 - __builtin_clz((x)) - 1)
#define log2ll(x) (64 - __builtin_clzll((x)) - 1)
#define Pi 3.141592653589793
#define sz(x) (int)x.size()
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
const int N = 5e5+7;
int n;
ll ans=0;
ll d[N];
priority_queue<ll> q;
int main() {
fastIO;
//freopen("test.inp","r",stdin);
//freopen("test.out","w",stdout);
cin >> n;
forw(i,1,n+1) {
int x,y; cin >> x >> y;
d[i]=d[i-1]+x-y;
}
forw(i,1,n+1) {
q.push(min(max(d[i],0ll),d[n]));
q.push(min(max(d[i],0ll),d[n]));
if(q.top()>d[i]) ans+=q.top()-d[i];
if(d[n]<d[i]) ans+=d[i]-d[n];
q.pop();
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
312 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
12 ms |
1620 KB |
Output is correct |
5 |
Correct |
30 ms |
2820 KB |
Output is correct |
6 |
Correct |
82 ms |
7808 KB |
Output is correct |
7 |
Correct |
141 ms |
15212 KB |
Output is correct |
8 |
Correct |
136 ms |
13244 KB |
Output is correct |
9 |
Correct |
141 ms |
12760 KB |
Output is correct |
10 |
Correct |
104 ms |
10336 KB |
Output is correct |
11 |
Correct |
105 ms |
10360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
312 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
12 ms |
1620 KB |
Output is correct |
5 |
Correct |
30 ms |
2820 KB |
Output is correct |
6 |
Correct |
82 ms |
7808 KB |
Output is correct |
7 |
Correct |
141 ms |
15212 KB |
Output is correct |
8 |
Correct |
136 ms |
13244 KB |
Output is correct |
9 |
Correct |
141 ms |
12760 KB |
Output is correct |
10 |
Correct |
104 ms |
10336 KB |
Output is correct |
11 |
Correct |
105 ms |
10360 KB |
Output is correct |
12 |
Correct |
45 ms |
4080 KB |
Output is correct |
13 |
Correct |
85 ms |
10944 KB |
Output is correct |
14 |
Correct |
144 ms |
15148 KB |
Output is correct |
15 |
Correct |
126 ms |
13408 KB |
Output is correct |
16 |
Correct |
131 ms |
12580 KB |
Output is correct |
17 |
Correct |
117 ms |
10344 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
312 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
352 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
312 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
352 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
336 KB |
Output is correct |
17 |
Correct |
3 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
312 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
352 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
12 ms |
1620 KB |
Output is correct |
12 |
Correct |
30 ms |
2820 KB |
Output is correct |
13 |
Correct |
82 ms |
7808 KB |
Output is correct |
14 |
Correct |
141 ms |
15212 KB |
Output is correct |
15 |
Correct |
136 ms |
13244 KB |
Output is correct |
16 |
Correct |
141 ms |
12760 KB |
Output is correct |
17 |
Correct |
104 ms |
10336 KB |
Output is correct |
18 |
Correct |
105 ms |
10360 KB |
Output is correct |
19 |
Correct |
45 ms |
4080 KB |
Output is correct |
20 |
Correct |
85 ms |
10944 KB |
Output is correct |
21 |
Correct |
144 ms |
15148 KB |
Output is correct |
22 |
Correct |
126 ms |
13408 KB |
Output is correct |
23 |
Correct |
131 ms |
12580 KB |
Output is correct |
24 |
Correct |
117 ms |
10344 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
3 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
30 |
Correct |
3 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
33 |
Correct |
44 ms |
4036 KB |
Output is correct |
34 |
Correct |
121 ms |
10996 KB |
Output is correct |
35 |
Correct |
176 ms |
15164 KB |
Output is correct |
36 |
Correct |
162 ms |
12724 KB |
Output is correct |
37 |
Correct |
149 ms |
13372 KB |
Output is correct |
38 |
Correct |
171 ms |
15168 KB |
Output is correct |
39 |
Correct |
119 ms |
11292 KB |
Output is correct |
40 |
Correct |
131 ms |
10936 KB |
Output is correct |
41 |
Correct |
117 ms |
10336 KB |
Output is correct |
42 |
Correct |
117 ms |
10428 KB |
Output is correct |
43 |
Correct |
112 ms |
10300 KB |
Output is correct |
44 |
Correct |
121 ms |
10480 KB |
Output is correct |
45 |
Correct |
151 ms |
15124 KB |
Output is correct |
46 |
Correct |
143 ms |
10720 KB |
Output is correct |
47 |
Correct |
121 ms |
10284 KB |
Output is correct |