Submission #567929

#TimeUsernameProblemLanguageResultExecution timeMemory
567929four_specksPotatoes and fertilizers (LMIO19_bulves)C++17
0 / 100
1 ms212 KiB
#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 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...