1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| #include<cstdio> #include<algorithm> #include<cmath> #include<iostream> #include<cstring> using namespace std; const int maxn=1e3; struct people{ int B,J; people(){} people(int B,int J):B(B),J(J){} bool operator < (const people& x)const{ return J>x.J; } }p[maxn]; int main(){ int n,b,j,cnt=0; while(scanf("%d",&n),n){ for(int i=0;i<n;i++){ scanf("%d%d",&b,&j); p[i]=people(b,j); } sort(p,p+n); long long ans=0,cur=0; for(int i=0;i<n;i++){ cur+=p[i].B; ans=max(ans,p[i].J+cur); } printf("Case %d: %lld\n",++cnt,ans); } return 0; }
|