///aureg109 orz
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define ii pair<int,int>
#define sz(x) (int) (x).size()
#define pb push_back
using namespace std;
template<class T1,class T2> bool maximize(T1 &a,T2 b) {return(a<b ? a=b,1:0);};
template<class T1,class T2> bool minimize(T1 &a,T2 b) {return(a>b ? a=b,1:0);};
int n;
ll d[500010],f;
void aureg109()
{
cin >> n;
for (int i=1;i<=n;i++)
{
ll a,b;
cin >> a >>b;
d[i]=d[i-1]+a-b;
}
priority_queue<ll> pq;
assert(d[n]>=0);
for (int i=1;i<=n;i++)
{
if (d[i]<0) f-=d[i],d[i]=0;
else f+=d[i];
pq.push(d[i]);
pq.push(d[i]);
pq.pop();
}
while(sz(pq))
{
f-=min(pq.top(),d[n]);
pq.pop();
}
cout <<f;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
aureg109();
}
# |
결과 |
실행 시간 |
메모리 |
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 |
13 ms |
1296 KB |
Output is correct |
5 |
Correct |
26 ms |
2216 KB |
Output is correct |
6 |
Correct |
79 ms |
4424 KB |
Output is correct |
7 |
Correct |
106 ms |
8392 KB |
Output is correct |
8 |
Correct |
142 ms |
8472 KB |
Output is correct |
9 |
Correct |
110 ms |
8468 KB |
Output is correct |
10 |
Correct |
98 ms |
8416 KB |
Output is correct |
11 |
Correct |
99 ms |
8468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
13 ms |
1296 KB |
Output is correct |
5 |
Correct |
26 ms |
2216 KB |
Output is correct |
6 |
Correct |
79 ms |
4424 KB |
Output is correct |
7 |
Correct |
106 ms |
8392 KB |
Output is correct |
8 |
Correct |
142 ms |
8472 KB |
Output is correct |
9 |
Correct |
110 ms |
8468 KB |
Output is correct |
10 |
Correct |
98 ms |
8416 KB |
Output is correct |
11 |
Correct |
99 ms |
8468 KB |
Output is correct |
12 |
Correct |
36 ms |
2384 KB |
Output is correct |
13 |
Correct |
93 ms |
6916 KB |
Output is correct |
14 |
Correct |
111 ms |
8408 KB |
Output is correct |
15 |
Correct |
148 ms |
8456 KB |
Output is correct |
16 |
Correct |
150 ms |
8356 KB |
Output is correct |
17 |
Correct |
88 ms |
8384 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
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 |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
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 |
13 ms |
1296 KB |
Output is correct |
12 |
Correct |
26 ms |
2216 KB |
Output is correct |
13 |
Correct |
79 ms |
4424 KB |
Output is correct |
14 |
Correct |
106 ms |
8392 KB |
Output is correct |
15 |
Correct |
142 ms |
8472 KB |
Output is correct |
16 |
Correct |
110 ms |
8468 KB |
Output is correct |
17 |
Correct |
98 ms |
8416 KB |
Output is correct |
18 |
Correct |
99 ms |
8468 KB |
Output is correct |
19 |
Correct |
36 ms |
2384 KB |
Output is correct |
20 |
Correct |
93 ms |
6916 KB |
Output is correct |
21 |
Correct |
111 ms |
8408 KB |
Output is correct |
22 |
Correct |
148 ms |
8456 KB |
Output is correct |
23 |
Correct |
150 ms |
8356 KB |
Output is correct |
24 |
Correct |
88 ms |
8384 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 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 |
38 ms |
2440 KB |
Output is correct |
34 |
Correct |
110 ms |
6880 KB |
Output is correct |
35 |
Correct |
164 ms |
8388 KB |
Output is correct |
36 |
Correct |
165 ms |
8420 KB |
Output is correct |
37 |
Correct |
165 ms |
8372 KB |
Output is correct |
38 |
Correct |
167 ms |
8392 KB |
Output is correct |
39 |
Correct |
108 ms |
8392 KB |
Output is correct |
40 |
Correct |
124 ms |
8104 KB |
Output is correct |
41 |
Correct |
95 ms |
8376 KB |
Output is correct |
42 |
Correct |
95 ms |
8392 KB |
Output is correct |
43 |
Correct |
93 ms |
8428 KB |
Output is correct |
44 |
Correct |
97 ms |
8460 KB |
Output is correct |
45 |
Correct |
155 ms |
8476 KB |
Output is correct |
46 |
Correct |
136 ms |
8376 KB |
Output is correct |
47 |
Correct |
107 ms |
7500 KB |
Output is correct |