This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <queue>
#define int long long
using namespace std;
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
priority_queue<int> q;
int pf = 0;
int v0 = 0;
for (int i = 0; i < n; i++)
{
int a, b;
cin >> a >> b;
int d = a - b;
pf += d;
q.push(max(0ll, pf));
q.push(max(0ll, pf));
q.pop();
v0 += abs(pf);
}
int res = v0;
while (q.size() > 0)
{
res -= min(q.top(), pf);
q.pop();
}
cout << res << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |