Submission #919088

#TimeUsernameProblemLanguageResultExecution timeMemory
919088imarnPotatoes and fertilizers (LMIO19_bulves)C++14
0 / 100
1 ms344 KiB
#include<bits/stdc++.h> #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define f first #define s second #define pb push_back #define all(x) x.begin(),x.end() #define vi vector<int> #define vvi vector<vi> #define vp vector<pii> using namespace std; priority_queue<ll>q; int main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n;cin>>n; ll dp[n+1]={0}; for(int i=1,a,b;i<=n;i++){ cin>>a>>b;dp[i]=a-b+dp[i-1]; }ll res=0; for(int i=1;i<n;i++){ res+=dp[i]; q.push(dp[i]); q.push(dp[i]); q.pop(); } while(!q.empty()){ res-=min(dp[n],q.top());q.pop(); }cout<<res; }
#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...