Production Line Finish Time
MediumSimulation ยท Plaid
Return the time at which the last of n jobs finishes the last stage of a production line. All jobs are ready for the first stage at time 0.
stages[i] = [workers, minutes] means stage i has that many workers, each handling one job at a time and taking exactly minutes per job. A job moves to the next stage the moment it finishes the current one, and a free worker starts a waiting job immediately. Return 0 if n is 0.
Example 1
- Input:
- n = 3, stages = [[2, 3], [1, 5]]
- Output:
- 18
- Explanation
- Stage 0 finishes jobs at times 3, 3 and 6. The single stage 1 worker then handles them at 3 to 8, 8 to 13 and 13 to 18.
Example 2
- Input:
- n = 4, stages = [[3, 2], [2, 3]]
- Output:
- 8
Example 3
- Input:
- n = 0, stages = [[2, 4]]
- Output:
- 0
Constraints
0 <= n <= 10^51 <= stages.length <= 101 <= workers <= 10^5and1 <= minutes <= 1000for every stage