#P2179. Optimal Cycling Strategy on the Sichuan-Tibet Route

    ID: 15460 Type: Default 1000ms 256MiB

Optimal Cycling Strategy on the Sichuan-Tibet Route

Optimal Cycling Strategy on the Sichuan-Tibet Route

Dandan is an avid cyclist who plans to challenge himself this summer by riding his bicycle from Chengdu to Lhasa along the Sichuan-Tibet route. The route is divided into n segments. For the ith segment, you are given three parameters: si (the length of the segment), ki (the wind resistance coefficient) and vi (the wind speed on that segment). Here, vi′ > 0 indicates that Dandan enjoys a tailwind on that segment, while vi′ ≤ 0 indicates a headwind.

When cycling at a constant speed v on a segment, the wind resistance force is given by \[ F = k_i\,(v - v_i' )^2, \] so the energy consumed over a distance s is \[ E = k_i (v - v_i')^2 s. \]

Dandan starts the day with a finite amount of energy E_U. He wishes to complete his journey in the shortest possible time. In each segment, his travel time is ti = si / vi if he rides at speed vi, and the energy consumed is Ei = ki(vi - vi′)2si. He must choose his speeds such that \[ \sum_{i=1}^{n} k_i\,(v_i - v_i')^2 s_i \le E_U. \] Your task is to decide the optimal constant speed vi for each segment so that the total time \[ T = \sum_{i=1}^{n} \frac{s_i}{v_i} \] is minimized, while ensuring the total energy expenditure does not exceed E_U. Output the minimum total time T achieving this goal.

inputFormat

The first line contains two numbers: an integer n (the number of segments) and a real number E_U (the total available energy).

Each of the following n lines contains three real numbers: si, ki and vi, representing the length of the segment, the wind resistance coefficient, and the wind speed on that segment, respectively.

outputFormat

Output a single real number: the minimum total time T required to complete the journey. Your answer is accepted if its absolute or relative error does not exceed 10-6.

sample

1 200
100 1 5
19.999999