#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 1;
int n;
long long a[N],ans,s;
priority_queue<long long> q;
vector<long long> v;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
for(int i = 1;i <= n;i++)
{
int x,y;
cin >> x >> y;
a[i] = x-y+a[i-1];
if(a[i]<0) ans-=a[i]-1,a[i] = 1;
s+=a[i];
q.push(a[i]),q.push(a[i]),q.pop();
a[i] = x-y+a[i-1];
}
while(!q.empty()) v.push_back(q.top()),q.pop();
reverse(v.begin(),v.end());
long long prev = 0;
for(auto x : v) s-=(n--)*(x-prev),prev = x;
cout << s+ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |