题目传送门
/*
贪心:按照执行时间长的优先来排序
*/
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;
const int MAXN = 1e3 + ;
const int INF = 0x3f3f3f3f;
struct Node {
int b, j;
bool operator < (const Node &r) const {
return j > r.j;
}
}node[MAXN];
int main(void) //UVA 11729 Commando War
{
//freopen ("UVA_11729.in", "r", stdin);
int n; int cas = ;
while (scanf ("%d", &n) == && n)
{
for (int i=; i<=n; ++i)
{
scanf ("%d%d", &node[i].b, &node[i].j);
}
sort (node+, node++n);
int ans = ; int mx = -;
for (int i=; i<=n; ++i)
{
ans += node[i].b;
mx = max (mx, ans + node[i].j);
}
printf ("Case %d: %d\n", ++cas, mx);
}
return ;
}
/*
Case 1: 8
Case 2: 15
*/