This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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++){
if(dp[i]<0)res-=dp[i],dp[i]=0;
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |