# | 제출 시각UTC-0 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
513014 | CrouchingDragon | Potatoes and fertilizers (LMIO19_bulves) | C++17 | 162 ms | 12540 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
pq.push(0);
int64_t sum = 0, cost = 0;
for (int i = 0; i < N - 1; ++i) {
sum += a[i];
pq.push(sum);
if (!pq.empty() && sum < pq.top()) {
cost += pq.top() - sum;
if (pq.top() != 0) pq.pop();
pq.push(sum);
}
}
sum += a[N - 1];
while (!pq.empty() && pq.top() > sum) {
cost += pq.top() - sum;
pq.pop();
}
std::cout << cost << '\n';
# | 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... |