Submission #964378

#TimeUsernameProblemLanguageResultExecution timeMemory
964378new_accPotatoes and fertilizers (LMIO19_bulves)C++14
100 / 100
278 ms34916 KiB
#include<bits/stdc++.h> #define fi first #define se second #define pitem item* using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; const int N=1e6+10; const int SS=1<<19; const int INFi=2e9; const ll INFl=1e16; const ll mod2=998244353; const ll mod=1e9+7; const ll mod3=2027865967; const ll p=70032301; const ull p2=913; const int L=20; int n; ll t[N]; void solve(){ cin>>n; for(int i=1;i<=n;i++){ int a,b; cin>>a>>b; t[i]=t[i-1]+a-b; } multiset<ll> c; c.insert(0); ll res=0; for(int i=1;i<n;i++){ auto it=c.end(); it--; ll val=t[i]; if(t[i]<0) res+=abs(t[i]),val=0; if((*it)>t[i]){ c.erase(it); res+=(*it)-val; c.insert(val),c.insert(val); }else c.insert(val); } auto it2=c.end(); it2--; auto it=c.end(); ll sl=0,pop=0; for(it--;(*it)>t[n];it--,sl++){ res+=sl*(pop-*it); pop=*it; } res+=sl*(pop-t[n]); cout<<res<<"\n"; } int main(){ ios_base::sync_with_stdio(0),cin.tie(0); int tt=1; while(tt--) 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...