#P7747. [COCI 2011/2012 #3] TRAKA
[COCI 2011/2012 #3] TRAKA
Description
There are workers in Mirko’s factory. They manufacture cars on a conveyor belt in an assembly-line manner. The workers are numbered from left to right as , and worker is Mirko. The production of a car starts with worker (Mirko). After he finishes all his work, worker takes over. Then worker takes over worker ’s work, and so on. When worker finishes his work, the car is completed.
Mirko and his workers must produce cars, and they must be produced in order from . For worker , the time needed to complete his part is . For car , its assembly complexity is . The time worker needs to finish his work on car is .
According to company policy, after a worker finishes his work, he must immediately pass the work to the next worker without any delay. Therefore, at that moment, the next worker must not be working on another car. To satisfy this condition, Mirko must wait for a suitable moment to start making a new car. To improve efficiency, he will wait the minimum amount of time until he is sure that all conditions can be satisfied.
Write a program that, given the time needed for each worker to complete his work and the assembly complexity of each car, computes the total time required to produce all cars.
Input Format
The input contains a total of lines.
The first line contains two integers , representing the number of workers and the number of cars to be produced.
The next lines each contain one integer , denoting the time needed for worker to complete his work.
The next lines each contain one integer , denoting the assembly complexity of car .
Output Format
Output a single line containing one integer, representing the total time required to produce all cars.
3 3
2
1
1
2
1
1
11
3 3
2
3
3
2
1
2
29
4 5
3
2
2
2
3
1
2
1
2
55
Hint
[Sample 1 Explanation]
For sample , after units of time, worker finishes his work on the first car. He could immediately start working on the second car, but that would violate the condition that a car must be passed to the next worker immediately after it is finished (after units of time, worker would finish his work on the second car, but worker cannot take over because he is still working on the first car). Therefore, the second car can only start production after units of time. The third car starts production after units of time. The first car is completed after units of time, the second car after units of time, and the third car after units of time. Therefore, the total time is .
[Constraints]
For of the testdata, .
For all testdata, , and .
[Source]
This problem comes from COCI 2011-2012 CONTEST 3 T6 TRAKA, using the original testdata configuration, with a full score of points.
Translated and organized by Eason_AC.
Translated by ChatGPT 5
京公网安备 11011102002149号