Problem here
Solution
N年冇寫
先水一題
xdd
按執行時間由大到小排序
找完成所有任務的總時間
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
bool cmp(pair<int, int>a , pair<int, int> ai){
return a.second > ai.second;
}
int main(){
int n, b, j;
int count = 0;
while(cin >> n){
vector<pair<int, int> > s;
if(n == 0)
break;
for(int i = 0; i < n; i++){
cin >> b >> j;
s.push_back(make_pair(b,j));
}
sort(s.begin(), s.end(), cmp);
int time = 0,tb = 0;
for(int i = 0; i < s.size(); i++){
tb += s[i].first;
time = max(time, tb+s[i].second);
}
cout << "Case " << ++count << ": " << time << endl;
}
return 0;
}