Submission #910432

#TimeUsernameProblemLanguageResultExecution timeMemory
910432panPotatoes and fertilizers (LMIO19_bulves)C++17
100 / 100
323 ms19228 KiB
#include <bits/stdc++.h> //#include "bits_stdc++.h" #define f first #define s second #define mp make_pair #define pb push_back #define lb lower_bound #define ub upper_bound #define show(x) cerr << #x << " is " << x << endl; #define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl; #define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl; using namespace std; typedef long long ll; typedef long double ld; typedef pair<ld, ll> pd; typedef pair<string, ll> psl; typedef pair<ll, ll> pi; typedef pair<ll, pi> pii; int main() { ll ans = 0; priority_queue<ll> pq; ll n, a, b; cin >> n; ll dif[n+1], ps[n+1]; ps[0]=0; for (ll i=1; i<=n; ++i) { cin >> a >> b; dif[i] = a-b; ps[i]= ps[i-1] + dif[i]; ans +=abs(ps[i]); pq.push(max(0LL, ps[i])); pq.push(max(0LL, ps[i])); pq.pop(); } for (ll i=0; i<n; ++i) {ans-=min(pq.top(), ps[n]); pq.pop();} cout << ans << endl; 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...