AcWing 125. 耍杂技的牛
原题链接
中等
作者:
跟着灿哥学切菜
,
2021-01-20 14:43:10
,
所有人可见
,
阅读 227
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int, int> PII;
const int N = 50010;
int n;
PII cow[N];
int main()
{
scanf("%d", &n);
for(int i = 0; i < n; i ++) {
int s, w;
scanf("%d%d", &w, &s);
cow[i] = {s + w, w};
}
sort(cow, cow + n);
int res = -2e9, sum = 0;
for (int i = 0; i < n; i ++) {
int s = cow[i].first - cow[i].second, w = cow[i].second;
res = max(res, sum - s);
sum += w;
}
printf("%d\n", res);
return 0;
}