您的位置:首页 > 其它

uva 11729

2015-09-12 15:44 381 查看
<pre name="code" class="cpp">#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <queue>
#include <map>
using namespace std;
const int MAXN = 1000 + 10;
const int MAXM = 1000000000 + 1000;
typedef long long LL;
/*
uva 11729
*/

int main(){
int N,Case=0;
scanf("%d",&N);		// N:number of soldiers
while( N!=0 ){
++Case;
multimap<int,int> m;
int B,J;
for(int i=0; i<N; i++){
cin >> B >> J;
m.insert(pair<int,int>(J,B));
}
multimap<int,int>::reverse_iterator rt = m.rbegin();
int total_need = 0, done_need = 0;
while( rt != m.rend() ){
int first = (*rt).first;
int second = (*rt).second;
total_need += second;
done_need = max(first,done_need-second);
rt++;
}
total_need += done_need;
cout << "Case " << Case << ": " << total_need << endl;
scanf("%d",&N);
}
return 0;
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: