在这里插入代码片#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 1e5 + 10;
typedef pair<int, int>PII;
PII a[N];
int n;
int main(){
cin>>n;
for(int i = 0; i < n; i ++ ){
int w, s;
cin>>w>>s;
a[i] = {w + s, w};
}
sort(a, a + n);
int res = -2e9, sum = 0;
for(int i = 0; i < n; i ++ ){
int s = a[i].first - a[i].second, w = a[i].second;
res = max(res, sum - s);
sum += w;
}
cout<<res<<endl;
return 0;
}
AcWing 125 耍杂技的牛 题解 (贪心—推公式)
最新推荐文章于 2024-10-01 05:07:35 发布