///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;
for (int i=1;i<=n;i++)
{
if (d[i]<0) f-=d[i],d[i]=0;
else f+=d[i];
pq.push(f);
pq.push(f);
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();
}
# |
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 |
13 ms |
1368 KB |
Output is correct |
5 |
Correct |
27 ms |
2260 KB |
Output is correct |
6 |
Correct |
72 ms |
4456 KB |
Output is correct |
7 |
Correct |
147 ms |
8392 KB |
Output is correct |
8 |
Correct |
137 ms |
8408 KB |
Output is correct |
9 |
Correct |
135 ms |
8464 KB |
Output is correct |
10 |
Correct |
126 ms |
8568 KB |
Output is correct |
11 |
Correct |
120 ms |
8388 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 |
13 ms |
1368 KB |
Output is correct |
5 |
Correct |
27 ms |
2260 KB |
Output is correct |
6 |
Correct |
72 ms |
4456 KB |
Output is correct |
7 |
Correct |
147 ms |
8392 KB |
Output is correct |
8 |
Correct |
137 ms |
8408 KB |
Output is correct |
9 |
Correct |
135 ms |
8464 KB |
Output is correct |
10 |
Correct |
126 ms |
8568 KB |
Output is correct |
11 |
Correct |
120 ms |
8388 KB |
Output is correct |
12 |
Incorrect |
35 ms |
2364 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |