uva 11729 - Commando War
水题怡情
1 #include<cstdio> 2 #include<algorithm> 3 #define maxn 1005 4 using namespace std; 5 struct war 6 { 7 int a,b; 8 bool operator<(const war &t)const 9 { 10 return b>t.b; 11 } 12 }wa[maxn]; 13 14 int main() 15 { 16 int n,ca=1; 17 while(scanf("%d",&n)&&n) 18 { 19 for(int i=0;i<n;i++)scanf("%d%d",&wa[i].a,&wa[i].b); 20 sort(wa,wa+n); 21 int ans=0,cur=0; 22 for(int i=0;i<n;i++) 23 { 24 cur+=wa[i].a; 25 ans=max(ans,cur+wa[i].b); 26 } 27 printf("Case %d: %d\n",ca++,ans); 28 } 29 return 0; 30 }