【題目敘述】http://tcgs.tc.edu.tw:1218/ShowProblem?problemid=h007
【解題想法】排序,Greedy
#include <iostream>
#include <queue>
using namespace std;
int main(){
int n, a, b, temp, ans;
priority_queue <pair<int, int> > pq;
while (cin >> n){
if (n == 0) break;
ans = 0;
temp = 0;
for (int i = 0; i < n; i++){
cin >> a >> b;
pq.push(make_pair(b, a));
}
while (!pq.empty()){
temp += pq.top().second;
ans = max(ans, temp+pq.top().first);
pq.pop();
}
cout << ans << "\n";
}
return 0;
}