一道简单的贪心,很容易想到,为了使得所有人执行完任务的总时间最短,需要先安排执行任务时间长的,所以按照J从大大小排序即可。
细节参见代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 5;
int n,m,kase=0;
struct node{
int a,b;
bool operator < (const node& rhs) const {
return b > rhs.b;
}
}a[maxn];
int main() {
while(~scanf("%d",&n)&&n) {
for(int i=0;i<n;i++) scanf("%d%d",&a[i].a,&a[i].b);
int ans = 0, rear = 0;
sort(a,a+n);
for(int i=0;i<n;i++) {
rear += a[i].a;
ans = max(ans,rear+a[i].b);
}
printf("Case %d: %d\n",++kase,ans);
}
return 0;
}