##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Repovive has built a gas station with several one-way lines.
There are cars. Car needs exactly minutes to refuel, and must leave the gas station no later than minutes after the process starts.
At the beginning, all lines are empty. The cars enter the gas station in the order . When a car enters, it must choose one of the lines and join the back of that line. Therefore, inside each line, the order of cars is the same as the order in which they entered the gas station.
All cars start refueling immediately after entering their chosen line. Cars in all lines can refuel at the same time. However, a car cannot leave before all cars in front of it in the same line have left.
More formally, suppose one line contains cars from front to back. Then car leaves at time
An assignment of cars to lines is valid if every car leaves at time at most .
Find the minimum possible number of lines such that there exists a valid assignment of the cars to exactly lines.
If all cars are placed in one line, their leaving times are , , and . All of them leave before their deadlines.
Use one line for cars and , and another line for cars and . Their leaving times are valid. One line is not enough because car would have to leave too late.
Three lines are enough: put cars , , and in one line, car in another line, and car in another line. The first three cars cannot be handled with fewer than three lines.