#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define debug(x) cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ld long double
#define nl '\n'
#define tb '\t'
#define sp ' '
using namespace std;
const int MX=3005, MOD=998244353, BLOCK=327, INF=1e9+7;
const ll INFF=1e18+7;
const ld ERR=1e-7, pi=3.14159265358979323846;
ll N, A, ans;
priority_queue<ll> best;
int main(){
fastio;
cin >> N;
for(ll i=1; i<=N; i++){
ll a, b;
cin >> a >> b;
A+=a-b;
ans+=abs(A);
if(A<0){
best.push(0);
best.push(0);
}else{
best.push(A);
best.push(A);
}
best.pop();
}
while(best.size()){
ans-=min(A, best.top());
best.pop();
}
cout << ans << nl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
16 ms |
884 KB |
Output is correct |
5 |
Correct |
29 ms |
2004 KB |
Output is correct |
6 |
Correct |
93 ms |
5744 KB |
Output is correct |
7 |
Correct |
125 ms |
11044 KB |
Output is correct |
8 |
Correct |
158 ms |
9220 KB |
Output is correct |
9 |
Correct |
130 ms |
8468 KB |
Output is correct |
10 |
Correct |
101 ms |
6196 KB |
Output is correct |
11 |
Correct |
104 ms |
6280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
16 ms |
884 KB |
Output is correct |
5 |
Correct |
29 ms |
2004 KB |
Output is correct |
6 |
Correct |
93 ms |
5744 KB |
Output is correct |
7 |
Correct |
125 ms |
11044 KB |
Output is correct |
8 |
Correct |
158 ms |
9220 KB |
Output is correct |
9 |
Correct |
130 ms |
8468 KB |
Output is correct |
10 |
Correct |
101 ms |
6196 KB |
Output is correct |
11 |
Correct |
104 ms |
6280 KB |
Output is correct |
12 |
Correct |
43 ms |
3072 KB |
Output is correct |
13 |
Correct |
125 ms |
8172 KB |
Output is correct |
14 |
Correct |
142 ms |
11036 KB |
Output is correct |
15 |
Correct |
177 ms |
9244 KB |
Output is correct |
16 |
Correct |
168 ms |
8532 KB |
Output is correct |
17 |
Correct |
104 ms |
6248 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
16 ms |
884 KB |
Output is correct |
12 |
Correct |
29 ms |
2004 KB |
Output is correct |
13 |
Correct |
93 ms |
5744 KB |
Output is correct |
14 |
Correct |
125 ms |
11044 KB |
Output is correct |
15 |
Correct |
158 ms |
9220 KB |
Output is correct |
16 |
Correct |
130 ms |
8468 KB |
Output is correct |
17 |
Correct |
101 ms |
6196 KB |
Output is correct |
18 |
Correct |
104 ms |
6280 KB |
Output is correct |
19 |
Correct |
43 ms |
3072 KB |
Output is correct |
20 |
Correct |
125 ms |
8172 KB |
Output is correct |
21 |
Correct |
142 ms |
11036 KB |
Output is correct |
22 |
Correct |
177 ms |
9244 KB |
Output is correct |
23 |
Correct |
168 ms |
8532 KB |
Output is correct |
24 |
Correct |
104 ms |
6248 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
44 ms |
3080 KB |
Output is correct |
34 |
Correct |
108 ms |
8228 KB |
Output is correct |
35 |
Correct |
198 ms |
11044 KB |
Output is correct |
36 |
Correct |
188 ms |
8756 KB |
Output is correct |
37 |
Correct |
164 ms |
9132 KB |
Output is correct |
38 |
Correct |
183 ms |
11060 KB |
Output is correct |
39 |
Correct |
115 ms |
7196 KB |
Output is correct |
40 |
Correct |
133 ms |
6728 KB |
Output is correct |
41 |
Correct |
106 ms |
6376 KB |
Output is correct |
42 |
Correct |
108 ms |
6260 KB |
Output is correct |
43 |
Correct |
101 ms |
6264 KB |
Output is correct |
44 |
Correct |
103 ms |
6244 KB |
Output is correct |
45 |
Correct |
180 ms |
10992 KB |
Output is correct |
46 |
Correct |
130 ms |
6568 KB |
Output is correct |
47 |
Correct |
121 ms |
6484 KB |
Output is correct |