Traffic Jam
Time limit2sMemory limit256 MB
Given the initial positions, lengths, and speeds of cars ahead on a straight road, find when the professor's car reaches coordinate S, given cars slow down to the car ahead when L meters apart.
- Level
Medium6 of 10
- Topics
- Simulation, Math, Array, Implementation
- Solved
- No attempts yet
Problem
In 2050, to improve road safety, overtaking was banned on all roads. On top of that, no car may come closer than L meters to the car in front, and cameras installed on every road monitor compliance with the rules. Unfortunately, these measures did not fully solve the problem of traffic jams.
Every morning Professor Svinkin drives from home to work. The road he takes is a straight line; we introduce a coordinate system on it with a unit of one meter, and represent cars as segments on this line that move in the direction of increasing coordinates.
Initially the professor's car is at the start of the road, so its front point is at the origin. The maximum speed of the professor's car is V meters per second.
Besides the professor's car, there are n other cars traveling along the road. While driving, each car tries to move at its own maximum speed. When car A catches up to the car B ahead of it, so that A's front point is exactly L meters from B's rear point, car A instantly reduces its speed to that of B and from then on repeats all of B's speed changes. No car leaves the road.
Find the time it takes Professor Svinkin to reach his work. He is considered to have arrived when the front point of his car reaches the point with coordinate S.
Input
The input contains several test cases. Each test case consists of several lines.
The first line contains four integers n, L, S, and V (1 ≤ n ≤ 10000, 1 ≤ L ≤ 1000, 1 ≤ S ≤ 10^9, 1 ≤ V ≤ 100). n is the number of cars ahead of the professor, L is the minimum distance between cars in meters, S is the distance from home to the professor's workplace, and V is the maximum speed of the professor's car in meters per second.
The following n lines each contain three integers x_i, l_i, and v_i (1 ≤ x_i ≤ 10^9, 1 ≤ l_i ≤ 10, 1 ≤ v_i ≤ 100). x_i is the coordinate of the front point of the i-th car at the initial moment, l_i is its length, and v_i is its maximum speed in meters per second.
The cars are given in order of increasing distance from the professor's car, and the distance between two neighboring cars at the initial moment is guaranteed to be at least L meters.
The last line of a test case contains four zeros. The total number of cars across all test cases does not exceed 10000.
Output
For each test case, print on a separate line the time in seconds it takes the professor to reach work. The answer must be printed with an absolute or relative error of at most 10^-5.