原题链接:
题解:
代码:
#include<bits/stdc++.h>
using namespace std;
const int N = 5e4 + 10;
using PII = pair<int, int>;
vector<PII> v;
int n, res = INT_MIN, sum;
int main() {
cin >> n;
for (int i = 0;i < n;i++) {
int w, s;cin >> w >> s;
v.push_back({w+s, s});
}
sort(v.begin(), v.end());
for (int i = 0;i < n;i++) {
res = max(res, sum - v[i].second);
sum += v[i].first - v[i].second;
}
cout << res;
}