代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 10010;
struct node{
int b, j;
bool operator < (const node t)const{
return j == t.j ? b < t.b : j > t.j;
}
};
node p[maxn];
int n, res, T;
int main(){
while(scanf("%d", &n) && n){
res = 0;
for(int i = 1; i <= n; i ++) scanf("%d%d", &p[i].b, &p[i].j);
sort(p+1, p+1+n);
int now = 0, res = 0;
for(int i = 1; i <= n; i ++){
res = max(res, now + p[i].b + p[i].j);
now += p[i].b;
}
printf("Case %d: ", ++T);
printf("%d\n", res);
}
return 0;
}