
There are k workers who want to move n boxes from the right (old) warehouse to the left (new) warehouse. You are given the two integers n and k , and a 2D integer array time of size k x 4 where time[i] = [right _i , pick _i , left _i , put _i ] .
The warehouses are separated by a river and connected by a bridge. Initially, all k workers are waiting on the left side of the bridge. To move the boxes, the i ^th worker can do the following:
Cross the bridge to the right side in right _i minutes.
Pick a box from the right warehouse in pick _i minutes.
Cross the bridge to the left side in left _i minutes.
Put the box into the left warehouse in put _i minutes.
The i ^th worker is less efficient than the j ^th worker if either condition is met:
left _i + right _i > left _j + right _j
left _i + right _i == left _j + right _j and i > j
The following rules regulate the movement of the workers through the bridge:
Only one worker can use the bridge at a time.
When the bridge is unused prioritize the least efficient worker (who have picked up the box) on the right side to cross. If not, prioritize the least efficient worker on the left side to cross.
If enough workers have already been dispatched from the left side to pick up all the remaining boxes, no more workers will be sent from the left side.
Return the elapsed minutes at which the last box reaches the left side of the bridge .
1 <= n, k <= 10 ^4time.length == ktime[i].length == 41 <= left _i , pick _i , right _i , put _i <= 1000