#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int dp[2][30005];
int n, A[500005], B[500005];
void solve(){
cin >> n;
for(int i = 1; i <= n; i++)cin >> A[i] >> B[i], A[i] -= B[i], A[i] += A[i - 1];
/*
for(int i = 1; i <= n; i++){
for(int j = 0; j <= 30000; j++){
if(j)dp[i & 1][j] = min(dp[i & 1][j - 1], dp[(i - 1) & 1][j] + abs(A[i] - j));
else dp[i & 1][j] = dp[(i - 1) & 1][j] + abs(A[i] - j);
}
}
*/
int ans = 0;
priority_queue <int> pq;
for(int i = 1; i <= n; i++){
pq.push(A[i]); pq.push(A[i]);
ans += abs(max(0ll, min(A[n], pq.top())) - A[i]);
pq.pop();
}
//while(!pq.empty() && pq.top() > A[n])ans -= (pq.top() - A[n]), pq.pop();
cout << ans;
//cout << dp[n & 1][A[n]];
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int tc = 1;
//cin >> tc;
for(int tc1=1;tc1<=tc;tc1++){
// cout << "Case #" << tc1 << ": ";
solve();
}
}
Compilation message
bulves.cpp:41:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
41 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
11 ms |
7392 KB |
Output is correct |
5 |
Correct |
20 ms |
8412 KB |
Output is correct |
6 |
Correct |
58 ms |
12156 KB |
Output is correct |
7 |
Correct |
113 ms |
21280 KB |
Output is correct |
8 |
Correct |
98 ms |
17728 KB |
Output is correct |
9 |
Correct |
116 ms |
16584 KB |
Output is correct |
10 |
Correct |
69 ms |
14536 KB |
Output is correct |
11 |
Correct |
73 ms |
15564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
11 ms |
7392 KB |
Output is correct |
5 |
Correct |
20 ms |
8412 KB |
Output is correct |
6 |
Correct |
58 ms |
12156 KB |
Output is correct |
7 |
Correct |
113 ms |
21280 KB |
Output is correct |
8 |
Correct |
98 ms |
17728 KB |
Output is correct |
9 |
Correct |
116 ms |
16584 KB |
Output is correct |
10 |
Correct |
69 ms |
14536 KB |
Output is correct |
11 |
Correct |
73 ms |
15564 KB |
Output is correct |
12 |
Correct |
32 ms |
9680 KB |
Output is correct |
13 |
Correct |
83 ms |
15308 KB |
Output is correct |
14 |
Correct |
112 ms |
20932 KB |
Output is correct |
15 |
Correct |
94 ms |
19196 KB |
Output is correct |
16 |
Correct |
103 ms |
18560 KB |
Output is correct |
17 |
Correct |
65 ms |
15820 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
2 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
11 ms |
7392 KB |
Output is correct |
12 |
Correct |
20 ms |
8412 KB |
Output is correct |
13 |
Correct |
58 ms |
12156 KB |
Output is correct |
14 |
Correct |
113 ms |
21280 KB |
Output is correct |
15 |
Correct |
98 ms |
17728 KB |
Output is correct |
16 |
Correct |
116 ms |
16584 KB |
Output is correct |
17 |
Correct |
69 ms |
14536 KB |
Output is correct |
18 |
Correct |
73 ms |
15564 KB |
Output is correct |
19 |
Correct |
32 ms |
9680 KB |
Output is correct |
20 |
Correct |
83 ms |
15308 KB |
Output is correct |
21 |
Correct |
112 ms |
20932 KB |
Output is correct |
22 |
Correct |
94 ms |
19196 KB |
Output is correct |
23 |
Correct |
103 ms |
18560 KB |
Output is correct |
24 |
Correct |
65 ms |
15820 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
2 ms |
2652 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
28 ms |
9436 KB |
Output is correct |
34 |
Correct |
67 ms |
15612 KB |
Output is correct |
35 |
Correct |
115 ms |
20324 KB |
Output is correct |
36 |
Correct |
103 ms |
17904 KB |
Output is correct |
37 |
Correct |
101 ms |
17444 KB |
Output is correct |
38 |
Correct |
109 ms |
20504 KB |
Output is correct |
39 |
Correct |
70 ms |
15484 KB |
Output is correct |
40 |
Correct |
81 ms |
15560 KB |
Output is correct |
41 |
Correct |
82 ms |
16516 KB |
Output is correct |
42 |
Correct |
74 ms |
15048 KB |
Output is correct |
43 |
Correct |
80 ms |
15048 KB |
Output is correct |
44 |
Correct |
71 ms |
15584 KB |
Output is correct |
45 |
Correct |
114 ms |
19656 KB |
Output is correct |
46 |
Correct |
92 ms |
16680 KB |
Output is correct |
47 |
Correct |
83 ms |
15464 KB |
Output is correct |