只能说,真的不好想明白orz
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
const int N = 50010;
typedef pair<int, int> PII;
PII cow[N];
int n;
int main(){
cin >> n;
for(int i = 0; i < n; i ++ ){
int w, s;
cin >> w >> s;
cow[i] = {w + s, w};
}
sort(cow, cow + n);
int res = -0x3f3f3f3f, sum = 0;
for(int i = 0; i < n; i ++ ){
int s = cow[i].x - cow[i].y, w = cow[i].y;
res = max(res, sum - s);
sum += w;
}
cout << res << endl;
return 0;
}