This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <algorithm> | |
using namespace std; | |
struct soldier{ | |
int B; | |
int J; | |
}a[10001]; | |
bool cmp(soldier a,soldier b){ | |
return a.J > b.J; | |
} | |
int main() | |
{ | |
int N,Case=1; | |
while (scanf("%d",&N)){ | |
if (N == 0) break; | |
for(int i=0;i<N;i++) scanf("%d%d",&a[i].B,&a[i].J); | |
sort (a,a+N,cmp); | |
int time=0; | |
int ans=0; | |
for (int i=0;i<N;i++) { | |
time += a[i].B; | |
ans = max(ans,time+a[i].J); | |
} | |
printf("Case %d: ",Case++); | |
printf("%d\n",ans); | |
} | |
return 0; | |
} |
沒有留言:
張貼留言