Submission #1164737

#TimeUsernameProblemLanguageResultExecution timeMemory
1164737AbdullahIshfaqPotatoes and fertilizers (LMIO19_bulves)C++20
100 / 100
97 ms10416 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define MOD 998244353 void solve(){ ll n, a, b, p = 0, ans = 0; cin >> n; vector<ll> tmp; for(int i = 0; i < n; i ++){ cin >> a >> b; p += a - b; tmp.push_back(p); } priority_queue<ll> pq; for(auto c : tmp){ if(c < 0){ ans += -c; c = 0; } else if(c > p){ ans += c - p; c = p; } pq.push(c); if(pq.top() > c){ ans += (pq.top() - c); pq.push(c); pq.pop(); } } cout << ans << '\n'; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int tests = 1; // cin >> tests; for(int i = 1; i <= tests; i ++) solve(); }
#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...