AcWing 125. 耍杂技的牛
原题链接
中等
作者:
最后五分钟
,
2024-04-13 00:54:34
,
所有人可见
,
阅读 6
#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
using namespace std;
const int N=5e5+10;
typedef pair<int,int> PII;
struct Node
{
int w,s;
}a[N];
bool cmp(Node a,Node b)
{
return a.s+a.w<b.s+b.w;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i].w>>a[i].s;
sort(a,a+n,cmp);
int sumw=0,res=-0x3f3f3f3f;
for(int i=0;i<n;i++)
{
res=max(res,sumw-a[i].s);
sumw+=a[i].w;
}
cout<<res<<endl;
return 0;
}