#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 |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |