Submission #473505

#TimeUsernameProblemLanguageResultExecution timeMemory
473505piotruloPotatoes and fertilizers (LMIO19_bulves)C++17
100 / 100
463 ms19376 KiB
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; vector<long long>s(n); for(auto &x: s){ int a,b; cin>>a>>b; x=a-b; } partial_sum(s.begin(),s.end(),s.begin()); long long t=0; priority_queue<long long,vector<long long>,greater<long long>>q; for(int i=0;i<n+2;i++){ q.push(1ll*0); } for(auto w : s){ q.pop(); t+=max(-w-q.top(), 0LL); q.push(-w); q.push(-w); } long long ctr=0; while(q.top()!=-s.back()){ auto x=q.top(); q.pop(); t+=ctr*(q.top()-x); ctr++; } cout<<t; }
#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...