Flow Shop
Time limit6sMemory limit512 MB
Given N jobs processed through M stages in the same order with per-job times, and a smallest-label-first queue rule at each stage, find each job's finish time.
- Level
Medium7 of 10
- Topics
- Simulation, Queue, Implementation
- Solved
- No attempts yet
Problem
A workshop builds custom swathers, the machines used to cut grain. Every swather goes through the same sequence of stages: a cutting bar is mounted, a grain belt is installed, a reel is fitted. The parts are customized for each buyer, so the same stage can take a different amount of time on different swathers.
swathers have been ordered and the manufacturing process has stages. Every swather passes through the stages in the same order, from stage 1 to stage .
Stage takes units of time on swather . The workers at a stage handle one swather at a time and never interrupt a job once they have started it. At time 0 all orders are waiting at stage 1. Whenever the workers at stage are idle and at least one swather is waiting there, they take the waiting swather with the smallest label; the swathers are labelled 1 to . Stage can start on a swather only after stage has finished that same swather.
Determine the time at which each swather is completed.
Input
The first line contains two integers and (), the number of swathers and the number of stages. Each of the next lines contains integers. The -th integer on the -th line is ().
Output
Print one line with integers , separated by single spaces, where is the time at which stage is completed for swather .