AcWing 125. 耍杂技的牛
原题链接
中等
作者:
ZhangQ
,
2022-02-26 10:48:50
,
所有人可见
,
阅读 154
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 50000;
typedef long long LL;
pair<int,int> p[N];
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
int w,s; //体重和承受度。
scanf("%d%d",&w,&s);
p[i].first = w+s;
p[i].second = s;
}
sort(p,p+n); //按W+S从小到大排序。
LL res= -2e9; //记录最小的最大风险值。
LL sum = 0;//记录上边牛的体重。
for(int i=0;i<n;i++)
{
res = max(res,sum-p[i].second);
int w = p[i].first - p[i].second;
sum+=w;
}
printf("%d",res);
return 0;
}