#P1870. Bus Arrival Time Simulation

    ID: 15153 Type: Default 1000ms 256MiB

Bus Arrival Time Simulation

Bus Arrival Time Simulation

There is a bus depot that can accommodate \( n \) buses. Every day, these buses leave the parking lot sequentially to head to a terminal station located at a distance of \( d \) meters. The \(i\)-th bus departs at time \( t_i \) seconds and can accelerate with a maximum acceleration of \( a \) (all buses share the same \( a \)) and has a speed limit of \( v_i \) meters/second. Initially, each bus starts with speed \( 0 \). A bus may accelerate at rate \( a \) until it reaches its speed limit and then continue at that speed. It can also decelerate instantly or change its acceleration instantaneously.

However, no bus is allowed to overtake the bus directly ahead. If a bus catches up with the bus in front, the two buses will drive together and reach the terminal at the same time. Each driver strives to reach the terminal as quickly as possible.

In the absence of any interference, the minimal travel time for a bus is determined as follows:

  • If the distance \( d \) is short such that the bus does not reach its maximum speed, its travel time equals \( \sqrt{\frac{2d}{a}} \).
  • If the bus can reach its maximum speed, it accelerates for \( \frac{v_i}{a} \) seconds (covering a distance of \( 0.5 \cdot \frac{v_i^2}{a} \)) and then travels the remaining distance at constant speed \( v_i \). In that case, the travel time is \( \frac{v_i}{a} + \frac{d - 0.5 \cdot \frac{v_i^2}{a}}{v_i} \).

Therefore, if the \(i\)-th bus would independently reach the terminal at time

\( T_i = t_i + \) (its computed travel time),

the actual arrival time is given by

\( A_i = \max(T_i, A_{i-1}) \), where \( A_{i-1} \) is the arrival time of the bus immediately ahead.

Input Format:
The first line contains three numbers: \( n \) (the number of buses), \( d \) (the distance to the terminal in meters), and \( a \) (the maximum acceleration in m/s²). This is followed by \( n \) lines, each containing two numbers: \( t_i \) and \( v_i \), the departure time in seconds and the maximum allowed speed (in m/s) of the \(i\)-th bus.

Output Format:
Output \( n \) lines, each line containing the minimal arrival time of the corresponding bus at the terminal (in seconds), printed to 6 decimal places.

inputFormat

The input begins with a single line containing three numbers: \( n \) (number of buses), \( d \) (distance to the terminal in meters), and \( a \) (maximum acceleration in m/s²). Following this, there are \( n \) lines where the \(i\)-th line contains two space-separated numbers \( t_i \) and \( v_i \), representing the departure time (in seconds) and the maximum speed (in m/s) of the \(i\)-th bus respectively.

outputFormat

Output \( n \) lines. The \(i\)-th line should contain the minimal arrival time (in seconds) of the \(i\)-th bus at the terminal, computed according to the constraints given. Each time should be printed with 6 decimal places.

sample

3 100 10
0 20
2 20
5 5
6.000000

8.000000 25.250000

</p>