← 返回 uber 的题目列表Last Truck to Leave a Lane
类型:online_judge
Last Truck to Leave a Lane
A one-dimensional lane spans [0, laneLength]. There are n trucks at distinct initial positions. Truck i starts at position[i] with velocity velocity[i]:
A positive velocity moves right.
A negative velocity moves left.
A truck leaves when it reaches or crosses 0 or laneLength.
When two trucks collide, they exchange velocities and directions.
Return the time when the last truck leaves the lane.
Assume all velocities are nonzero and no undefined multi-truck simultaneous collision needs to be handled.
Example
Input
2 10
2 1
8 -2
Output
8