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];
if (d < 0)
{
cost -= d;
d = 0;
}
else if (d > c)
{
cost += d - c;
d = c;
}
pq.push(d), pq.push(d);
cost += pq.top() - d;
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... |