Submission #1098693

#TimeUsernameProblemLanguageResultExecution timeMemory
1098693noyancanturkPotatoes and fertilizers (LMIO19_bulves)C++17
100 / 100
128 ms27080 KiB
#include "bits/stdc++.h" using namespace std; #define int int64_t #define pb push_back using pii=pair<int,int>; const int lim=2e5+100; const int mod=1e9+7; signed main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #ifdef Local freopen(".in","r",stdin);freopen(".out","w",stdout); #endif int n; cin>>n; int a[n+1],b[n+1]; for(int i=1;i<=n;i++)cin>>a[i]>>b[i]; int d[n+1]; for(int i=1;i<=n;i++)d[i]=a[i]-b[i]; int p[n+1]; p[0]=0; for(int i=1;i<=n;i++)p[i]=p[i-1]+d[i]; priority_queue<int>pq; int ans=0; for(int i=1;i<=n;i++){ if(p[i]<0){ if(pq.size()){ ans+=pq.top(); pq.pop(); } ans-=p[i]; }else{ pq.push(p[i]); ans+=pq.top()-p[i]; pq.push(p[i]); pq.pop(); } } while(p[n]<pq.top()){ ans+=pq.top()-p[n]; pq.pop(); } cout<<ans; }
#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...