COCI '11 Contest 3 #6 Traka
View as PDFAs mentioned before, there are  workers in Mirko's factory. They are manufacturing cars on a
conveyor belt, in a pipeline fashion. Workers are denoted by numbers 
 – leftmost, to 
 - rightmost.
Each of the workers does his specific job and requires certain amount of time to complete it.
Production of a single car starts with worker # (Mirko). After he had finished with his part of the job,
worker #
 takes over, after him #
... When worker #
 finishes with his part, the car is finished. Mirko
and his workers have to produce 
 cars and they must produce them in order 
 to 
.
For every worker  we know 
 - time required for him to do his part of the job. For every car 
 we
know factor of assembly complexity 
. Time in minutes for worker 
 to finish his part of the job on the
car 
 is computed as a product 
.
After some worker has finished working on a car, he has to give it to the next worker instantly, without any delay (weird company policy). For that reason, the worker receiving the car has to be free (he must not be working on some other car). In order to fulfill this condition, Mirko has to choose a good timing to start building a new car. To be efficient, he'll wait the minimum number of minutes until he is certain that all of the conditions described are met.
Write a program which will, given worker times and factors of complexity for each car, compute total time required for producing all of the cars.
Input Specification
First line of input contains space-separated positive integers  
, number of workers,
and 
 
, number of cars.
-th of the following 
 lines contains worker time 
 for the worker 
.
-th of the following 
 lines contains factor of complexity 
 for the car 
.
These conditions hold: , 
.
Output Specification
First and only line of output has to contain required number of minutes.
Scoring
In test cases worth  of total points, 
 and 
 will be at most 
.
Sample Input 1
3 3
2
1
1
2
1
1
Sample Output 1
11
Explanation for Sample Output 1
After four minutes, first worker finishes working on the first car. He might
start working on the second car immediately, but that would violate a condition that cars have to be
passed to next workers as soon as they're done (after seven minutes second worker would finish
working on his part of second car, but the third worker would not be free to take over as he would still
be working on the first car). That is the reason production of the second car is started after five
minutes. Production of the third car starts after seven minutes. First car is finished after eight, second
after nine and third after eleven seconds. Total time is then .
Sample Input 2
3 3
2
3
3
2
1
2
Sample Output 2
29
Sample Input 3
4 5
3
2
2
2
3
1
2
1
2
Sample Output 3
55
Comments