uva11729
题意:有n个人需要你分配任务,交代任务需要bi时间,执行任务需要ji时间,要求最早完成任务,请输出最后完成对的工作的时间。
类型:贪心(先排序再处理)
代码:
#include
#include
#include
#include
using namespace std;
int max(int a, int b){
return a>b?a:b;
}
struct job{
int j, b;
bool operator < (const job& x) const{
return j > x.j;
}
};
int main(){
// freopen("in.txt", "r", stdin);
int n, b, j;
int kase = 1;
while(scanf("%d", &n)!=EOF && n){
vectorvj;
int i;
for(i=0; i
cin >> b >> j;
job tj;
tj.b = b;
tj.j = j;
vj.push_back(tj);
}
sort(vj.begin(), vj.end());
int s = 0;
int ans = 0;
for(i=0; i
s += vj[i].b;
ans = max(ans, s+vj[i].j);
}
printf("Case %d: %d\n", kase++, ans);
}
}
Greatness is never a given, it must be earned.

浙公网安备 33010602011771号