显示代码纯文本
#include<cstdio>
#include<algorithm>
using namespace std;
struct task{
int t1,t2;
bool operator <(const task &a)const{
return t2>a.t2;
}
}lst[1005];
int max(int a,int b){
return a>b?a:b;
}
int main(){
freopen("commando.in","r",stdin);
freopen("commando.out","w",stdout);
int n,k=1;;
while(scanf("%d",&n),n!=0){
for(int i=1;i<=n;++i){
scanf("%d %d",&lst[i].t1,&lst[i].t2);
}
sort(lst+1,lst+n+1);
int now=0;
int ans=0;
for(int i=1;i<=n;++i){
ans=max(ans,now+lst[i].t1+lst[i].t2);
now+=lst[i].t1;
}
printf("Case %d: %d\n",k++,ans);
}
fclose(stdin);fclose(stdout);
return 0;
}