Sequential Manufacturing
Time limit1sMemory limit1024 MB
Given machine times T_i and input buffer sizes K_i, find the minimum total time to finish P goods without the system shutting down.
Problem
A manufacturing process consists of different machines. Raw material passes through the machines in order until it becomes a finished good. Machine takes seconds to process a good once it is input.
A good moves through the system automatically after it enters the first machine. To give the system some slack, each machine has an input area that holds up to goods waiting to be processed by that machine. When machine finishes a good, the good moves on to machine right away if that machine is free. Otherwise it waits in the input area of machine until the machine becomes free. If machine finishes a good while machine is busy and its input area is full, the system shuts down. If machines and finish goods at the same moment, the good from machine does not need to go through the input area of machine first.
You just received a huge order. You have an infinite supply of raw material, and you can choose the times at which goods enter machine 1. How quickly can you finish all of these goods without the system shutting down?
Input
The first line contains two integers (), the number of machines, and (), the number of goods to produce.
The next line contains the processing times (), all integers.
The next line contains the sizes of the input areas (), all integers. The first machine has no input area.
Output
Output the number of seconds needed to produce all goods. Manufacturing is complete when the last good is processed by the last machine.