题目地址:http://vjudge.net/problem/UVA-11729
#include <bits/stdc++.h>
using namespace std;
const int maxn=10000+5;
struct Job
{
int B,J;
bool operator < (const Job& job) const{
return J>job.J;
}
}jobs[maxn];
int main(int argc, char const *argv[])
{
int N,kase=0;
while(scanf("%d",&N)==1,N)
{
for(int i=0;i<N;i++)
scanf("%d%d",&jobs[i].B,&jobs[i].J);
sort(jobs,jobs+N);
int ans=jobs[0].J+jobs[0].B,pj=jobs[0].J,b,j;
for(int i=1;i<N;i++){
b=jobs[i].B;
j=jobs[i].J;
if(b+j<=pj) pj=pj-b;
else {
ans+=b+j-pj;
pj=j;
}
}
printf("Case %d: %d\n",++kase,ans);
}
return 0;
}