You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
835 B

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int N = 50010;
PII cow[N];
int n;
int main() {
cin >> n; //奶牛的数量
for (int i = 0; i < n; i++) {
int s, w; //牛的重量和强壮程度
cin >> w >> s;
cow[i] = {w + s, w}; //之所以这样记录数据,是因为我们找到贪心的公式,按 wi+si排序
}
//排序
sort(cow, cow + n);
//最大风险值
int res = -INF, 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); //res为最大风险值
sum += w; //sum=w1+w2+w3+...+wi
}
printf("%d\n", res);
return 0;
}