题目大意:N 个人,向每个人描述问题要 B 秒,完成问题要 J 秒,问最短时间。
解题思路:描述问题后就开始工作,但是描述不能同时进行,因此 B 的大小不重要。以 J 的大小降序排序,越长时间的让他越早开始任务。记录当前人完成任务的时间,若下一个人的时间超过当前最长时间,则最长时间增加。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
struct node {
int r;
int t;
};
int cmp (node a, node b) {
return a.t > b.t;
}
node p[100000];
int cnt = 0;
int main() {
int N;
while (scanf("%d", &N) != EOF && N) {
int B, J;
for (int i = 0; i < N; i++) {
scanf("%d%d", &p[i].r, &p[i].t);
}
sort(p, p+N, cmp);
int time = 0;
int MAX = 0;
for (int i = 0; i < N; i++) {
time += p[i].r;
if (MAX < p[i].t + time)
MAX = p[i].t + time;
}
printf("Case %d: %d\n", ++cnt, MAX);
}
return 0;
}