Submission #513014

#TimeUsernameProblemLanguageResultExecution timeMemory
513014CrouchingDragonPotatoes and fertilizers (LMIO19_bulves)C++17
100 / 100
162 ms12540 KiB
#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'; exit(0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...