##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
We process the cars in the given order .
First, let us understand what information we need to keep for one line.
Suppose a line currently contains some cars. Let be the maximum value of among all cars already placed in this line.
Now we want to put car at the back of this line.
The leaving time of car will be the maximum refueling time among all cars before it in this line and itself. So this leaving time is exactly .
Since the input guarantees , the value itself is never a problem. Therefore, car can be added to this line if and only if .
After adding car , the new value of this line becomes .
So each line can be represented by only one number: the maximum value of cars currently placed in that line.