#include <bits/stdc++.h>
using namespace std;
long long c[500001], ans = 0;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
long long a, b;
cin >> a >> b;
c[i] = c[i - 1] + a - b;
}
priority_queue<long long> pq;
for (int i = 1; i <= n; i++) {
if (c[i] > c[n]) {
ans += c[i] - c[n];
c[i] = c[n];
} else if (c[i] < 0) ans -= c[i];
pq.push(c[i]); pq.push(c[i]);
ans += pq.top() - c[i];
pq.pop();
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Incorrect |
6 ms |
376 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Incorrect |
6 ms |
376 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Incorrect |
5 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Incorrect |
6 ms |
376 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Incorrect |
6 ms |
376 KB |
Output isn't correct |