#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
#define int long long
#define N 200010
struct people {
int head, str;
}p[N];
int n;
bool cmp(people x, people y) {
if(x.str != y.str) {
return x.str > y.str;//肩高的垫底
} else {
return x.head < y.head;//头高的放后面
}
}
signed main()
{
cin >> n;
for(int i = 1;i <= n;i++) {
cin >> p[i].str >> p[i].head;
}
sort(p + 1, p + n + 1, cmp);
//加和
int sum = 0;
for(int i = 1;i < n/*不包括最后一个巨人*/;i++) {
sum += p[i].str;
}
cout << sum + p[n].head << "\n";
return 0;
}
样例全过