A factory is running a production line that requires two operations to be performed on each job: first operation "A" then operation "B". Only a certain number of machines are capable of performing each operation.

Give the earliest time operation "A" can be completed for all N jobs provided that the jobs are available at time 0. Compute the minimal amount of time that is necessary to perform both operations (successively, of course) on all N jobs.
PROGRAM NAME: job
INPUT FORMAT
Line 1: | Three space-separated integers:
|
Line 2..etc: | M1 integers that are the job processing times of each type "A" machine (1..20) followed by M2 integers, the job processing times of each type "B" machine (1..20). |
SAMPLE INPUT (file job.in)
5 2 3 1 1 3 1 4
OUTPUT FORMAT
A single line containing two integers: the minimum time to perform all "A" tasks and the minimum time to perform all "B" tasks (which require "A" tasks, of course).SAMPLE OUTPUT (file job.out)
3 5
第一问:
考虑到每一个工件都是独立的然后我想到了NOIP普及组一道,好像是water??
不管
贪心!
就是每次加最少的地方去加
然后就解决了。
第二问:
不会。
还是贪心。
注意:(每一个工件都是独立的)
考虑对于A处理n个工件,每一个工件都有一定的处理完A的时间
最短的处理完B的时间
类似这样:(可能机器比较少)
1:———
2:—————
3:——————
_1:—
_2:———
_3:————
显然,最大和最小的匹配比较好。
题解真妙,好好理解!
/*
ID:cqz15311
LANG:C++
PROG:job
*/
#include<bits/stdc++.h>
const int inf = 1 << 20;
using namespace std;
int a[1005],b[1005];
int timea[1005],timeb[1005],time1[1005],time2[1005];
int n,na,nb,Min,ans,k;
int main(){
freopen("job.in","r",stdin);
freopen("job.out","w",stdout);
scanf("%d",&n);
scanf("%d%d",&na,&nb);
for (int i=1;i<=na;i++) scanf("%d",&a[i]);
for (int i=1;i<=nb;i++) scanf("%d",&b[i]);
memset(timea,0,sizeof(timea));
memset(timeb,0,sizeof(timeb));
for (int i=1;i<=n;i++) {
Min = inf;
for (int j=1;j<=na;j++){
if (timea[j] + a[j] < Min) {
Min = timea[j] + a[j];
k = j;
}
}
timea[k] = time1[i] = Min;
}
printf("%d ",Min);
for (int i=1;i<=n;i++){
Min = inf;
for (int j=1;j<=nb;j++){
if (timeb[j] + b[j] < Min){
Min = timeb[j] + b[j];
k = j;
}
}
timeb[k] = time2[i] = Min;
}
ans = 0;
for (int i=1;i<=n;i++)
ans = max(ans,time1[i] + time2[n-i+1]);
printf("%d\n",ans);
fclose(stdin);
fclose(stdout);
}
/*
Executing...
Test 1: TEST OK [0.000 secs, 4196 KB]
Test 2: TEST OK [0.000 secs, 4196 KB]
Test 3: TEST OK [0.000 secs, 4196 KB]
Test 4: TEST OK [0.000 secs, 4196 KB]
Test 5: TEST OK [0.000 secs, 4196 KB]
Test 6: TEST OK [0.000 secs, 4196 KB]
Test 7: TEST OK [0.000 secs, 4196 KB]
Test 8: TEST OK [0.000 secs, 4196 KB]
Test 9: TEST OK [0.000 secs, 4196 KB]
Test 10: TEST OK [0.000 secs, 4196 KB]
Test 11: TEST OK [0.000 secs, 4196 KB]
Test 12: TEST OK [0.000 secs, 4196 KB]
All tests OK.
*/