Submission #800375

#TimeUsernameProblemLanguageResultExecution timeMemory
800375leeminhduc2Potatoes and fertilizers (LMIO19_bulves)C++17
24 / 100
147 ms8568 KiB
///aureg109 orz #include <bits/stdc++.h> #define ll long long #define f first #define s second #define ii pair<int,int> #define sz(x) (int) (x).size() #define pb push_back using namespace std; template<class T1,class T2> bool maximize(T1 &a,T2 b) {return(a<b ? a=b,1:0);}; template<class T1,class T2> bool minimize(T1 &a,T2 b) {return(a>b ? a=b,1:0);}; int n; ll d[500010],f; void aureg109() { cin >> n; for (int i=1;i<=n;i++) { ll a,b; cin >> a >>b; d[i]=d[i-1]+a-b; } priority_queue<ll> pq; for (int i=1;i<=n;i++) { if (d[i]<0) f-=d[i],d[i]=0; else f+=d[i]; pq.push(f); pq.push(f); pq.pop(); } while(sz(pq)) { f-=min(pq.top(),d[n]); pq.pop(); } cout <<f; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); aureg109(); }
#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...