#B4196. Race Car Meeting

    ID: 11853 Type: Default 1000ms 256MiB

Race Car Meeting

Race Car Meeting

Tao Tao and Tian Tian love racing games. In their game there is a straight track of length \(l\). Tao Tao's car starts at position 0 and heads toward the finish line at \(l\), while Tian Tian's car starts at \(l\) and heads toward the start at 0. Both cars start with an initial speed of 1. There are \(n\) acceleration zones located at positions \(a_1, a_2, \ldots, a_n\). When a car passes an acceleration zone, its speed increases by 1 immediately. Compute the time at which the two cars meet.

The meeting condition can be derived as follows. Let \(f_1(T)\) be the distance the first car travels in time \(T\) and let \(f_2(T)\) be the distance the second car travels (from the finish line toward 0) in time \(T\). Note that the position of the second car is \(l - f_2(T)\). They meet when \(f_1(T) = l - f_2(T)\), or equivalently, \(f_1(T) + f_2(T) = l\).

Details on the speed progression:

  • For the first car starting from 0, the car travels from one acceleration zone to the next. Suppose the car is at position \(p\) with speed \(v\). To reach the next acceleration zone at position \(q\), it takes \(\frac{q-p}{v}\) seconds. Upon reaching \(q\), its speed increases to \(v+1\).
  • A similar process occurs for the second car starting from \(l\) and moving toward 0 (using the acceleration zones in reverse order).

The most straightforward approach is to use binary search for \(T\). For a given \(T\), simulate the distance each car covers using the rules described and check if \(f_1(T)+f_2(T) = l\) (within acceptable precision). The answer is accepted if the absolute or relative error does not exceed \(10^{-7}\).

inputFormat

The first line contains two numbers: an integer \(n\) (the number of acceleration zones) and a real number \(l\) (the length of the track).

The second line contains \(n\) space-separated real numbers \(a_1, a_2, \ldots, a_n\) in strictly increasing order, representing the positions of the acceleration zones.

outputFormat

Output the time when the two cars meet. The answer is accepted if its absolute or relative error does not exceed \(10^{-7}\).

sample

3 10
2 4 7
3.6000000000