이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define szz(r) (ll)r.size()
#define vi vector<int>
#define vvi vector<vi>
#define pp pair<ll,int>
#define ub(x,i) upper_bound(all(x),i)-x.begin()
using namespace std;
const int mxn=3e5+5;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n;cin>>n;
int a[n+1],b[n+1];
ll d[n+1]={0};
for(int i=1;i<=n;i++)cin>>a[i]>>b[i],d[i]=d[i-1]+a[i]-b[i];
priority_queue<ll>pq;ll rs=0;
for(int i=1;i<n;i++){
if(d[i]<0)rs-=d[i],d[i]-=d[i];
rs+=d[i];
pq.push(d[i]);
pq.push(d[i]);
pq.pop();
}
while(!pq.empty()){
rs -= min(d[n],pq.top());
pq.pop();
}cout<<rs;
}
# | 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... |