Skip to content

Instantly share code, notes, and snippets.

@KT-Yeh
Created January 19, 2014 08:25
Show Gist options
  • Save KT-Yeh/8501942 to your computer and use it in GitHub Desktop.
Save KT-Yeh/8501942 to your computer and use it in GitHub Desktop.
#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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment