Submission #629497

#TimeUsernameProblemLanguageResultExecution timeMemory
629497PiokemonPotatoes and fertilizers (LMIO19_bulves)C++17
20 / 100
7 ms1236 KiB
#include <bits/stdc++.h> using namespace std; int c[500'009]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,a,b,odp = 0; cin >> n; c[0] = 0; for (int x=1;x<=n;x++){ cin >> a >> b; c[x] = a-b; //c[x] -= x; c[x] += c[x-1]; } priority_queue<int> slope; slope.push(0); for (int x=1;x<=n;x++){ if (c[x] < 0){ odp += 0 - c[x]; c[x] = 0; } if (c[x] > c[n]){ odp += c[x] - c[n]; c[x] = c[n]; } slope.push(c[x]); if (c[x] < slope.top()){ odp += slope.top() - c[x]; slope.pop(); slope.push(c[x]); } } cout << odp << "\n"; 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...