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>
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int N;
std::cin >> N;
std::vector<int64_t> a(N);
for (int i = 0; i < N; ++i) {
int64_t x, y;
std::cin >> x >> y;
a[i] = x - y;
}
std::priority_queue<int64_t> pq;
int64_t sum = 0, cost = 0;
for (int i = 0; i < N - 1; ++i) {
sum += a[i];
int64_t x = sum < 0 ? (cost += -sum, 0) : sum;
pq.push(x);
if (!pq.empty() && x < pq.top()) {
cost += pq.top() - x;
pq.pop();
pq.push(x);
}
}
sum += a[N - 1];
while (!pq.empty() && pq.top() > sum) {
cost += pq.top() - sum;
pq.pop();
}
std::cout << cost << '\n';
exit(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... |