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 <bits/stdc++.h>
using namespace std;
inline namespace
{
} // namespace
void solve()
{
int n;
cin >> n;
vector<long> a(n), b(n);
for (int i = 0; i < n; i++)
cin >> a[i] >> b[i];
long c = 0;
for (int i = 0; i < n; i++)
c += a[i] - b[i];
long cost = 0;
priority_queue<long> pq;
long d = 0;
for (int i = 0; i < n; i++)
{
d += a[i] - b[i];
long e = d;
if (e < 0)
{
cost -= e;
e = 0;
}
else if (e > c)
{
cost += e - c;
e = c;
}
pq.push(e), pq.push(e);
cost += pq.top() - e;
pq.pop();
}
cout << cost << '\n';
}
int main()
{
ios_base::sync_with_stdio(false), cin.tie(NULL);
solve();
return 0;
}
# | 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... |