이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lld long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define IShowSpeed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int N=5e5+10;
const int K=505;
const int mod=1e9+7;
const ll inf=1e18+228;
const int dx[]={-1,0,0,1};
const int dy[]={0,-1,1,0};
ll sum[N],n,ans=0,mx=0;
pair<ll,ll>h[N];
int main()
{
IShowSpeed
cin>>n;
for(int i=1;i<=n;i++) cin>>h[i].F>>h[i].S;
sort(h+1,h+n+1);
for(int i=1;i<=n;i++) sum[i]=sum[i-1]+h[i].S;
for(int i=1;i<=n;i++)
{
mx=max(mx,h[i].F-sum[i-1]);
ans=max(ans,sum[i]-h[i].F+mx);
}
cout<<ans;
}
/*
0 14
1 5 11
4 6 12
4 8 13
5 11 12
9 12 12
10 15 15
*/
# | 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... |