Submission #1294768

#TimeUsernameProblemLanguageResultExecution timeMemory
1294768dooweyPotatoes and fertilizers (LMIO19_bulves)C++20
100 / 100
132 ms4668 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); int main(){ fastIO; int n; cin >> n; ll a, b; priority_queue<ll> que; vector<ll> P; ll p = 0; ll low = 0; ll ans = 0; for(int i = 1; i <= n; i ++ ){ cin >> a >> b; p += a - b; ll d = max(p,0ll); ans += d - p; if(i < n){ que.push(d); que.push(d); ans += que.top() - d; que.pop(); } } ll xx = (ll)1e12; int coeff = 0; while(!que.empty() && que.top() > p){ ans += (xx - que.top()) * coeff; xx = que.top(); que.pop(); coeff ++ ; } ans += (xx - p) * coeff; cout << ans << "\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...