eolymp
bolt
Try our new interface for solving problems
Problems

Barcelona`s trams

Barcelona`s trams

\includegraphics{https://static.e-olymp.com/content/7a/7ac24696eb098f949ceb367b86de2dd2bf13b3fc.jpg} Quite recently the City of Barcelona has included trams to its "efficient" public transport. As expected, the result has been a nice set of accidents of outstanding originality and beauty. Diminishing aesthetic reasons, the Major of Barcelona has decided to reduce the delay caused by the accidents. After a thorough study the following model has been established: Every tram must go from an initial point \textbf{P_0} to a final point \textbf{P_n} visiting the intermediate points \textbf{P_1}, ..., \textbf{P_\{n-1\}} in this order. For every \textbf{1} ≤ \textbf{i} ≤ \textbf{n}, let \textbf{S_i} be the section going from \textbf{P_\{i-1\}} to \textbf{P_i}. Every such section must be traveled at uniform speed \textbf{v_i}, which is chosen by the driver at \textbf{P_\{i-1\}}. Let \textbf{M_i} be the maximum possible speed of the tram at \textbf{S_i}, and assume that the chosen speed is \textbf{0} < \textbf{v_i} ≤ \textbf{M_i}. Then the probability of crashing in \textbf{S_i} is \textbf{v_i/M_i}. When a crash happens, the tram uses an efficient recovery system that lasts only \textbf{10} seconds. Afterwards, the tram reaches \textbf{P_i} using an auxiliary (slow but safe) engine, which provides a speed of \textbf{5} meters per second and guarantees no more crashes in \textbf{S_i}. For instance, assume that the section length is \textbf{300} meters, and that the current maximum speed is \textbf{25} meters per second. If the driver chooses to travel at \textbf{25} m/s, the tram will crash for sure. Since the crash can happen anywhere between \textbf{P_\{i-1\}} and \textbf{P_i}, for the sake of computation we can assume that it will take place exactly in the middle point (after \textbf{150} meters). Therefore, on the average the tram will spend \textbf{6} seconds to reach the middle point, \textbf{10} seconds to recover from the crash, and \textbf{30} seconds to reach \textbf{P_i}, for a total of \textbf{46} seconds. By contrast, if the tram starts traveling at \textbf{15} m/s, with probability \textbf{0.6} it will crash and spend \textbf{10 + 10 + 30 = 50} seconds, and with probability \textbf{0.4} it will reach \textbf{P_i} after \textbf{20} seconds without any crash. The average time in this case is thus just \textbf{0.6·50 + 0.4·20 = 38} seconds. When the tram reaches every \textbf{P_i}, it stops for a few seconds regardless of having had a crash in \textbf{S_i} or not; these few seconds (for simplicity we consider them to be \textbf{0}) are enough to (almost) repair the tram: the maximum speed reduces by \textbf{1} m/s after every crash. If we call the initial maximum speed \textbf{M_0}, then we have \textbf{M_i = M_0 - C_i}, where \textbf{0} ≤ \textbf{C_i} ≤ \textbf{i-1} is the total number of crashes suffered in \textbf{S_1}, ..., \textbf{S_\{i-1\}}. Write a program that prints the optimal average travel time given the initial maximum speed and the length of every section. \InputFile Each line corresponds to one test case and contains the initial maximum speed \textbf{M_0} (a real number between \textbf{5} and \textbf{25}), the value of \textbf{n} (an integer number between \textbf{1} and \textbf{M_0} - \textbf{1}), and the length of every section (each is a real number between \textbf{100} and \textbf{1000}). \OutputFile For every test case, print the optimal average travel time with four decimal digits.
Time limit 1 second
Memory limit 64 MiB
Input example #1
25 1 900
25 2 900 900
25 2 305.15 980.76
5 1 1000
Output example #1
102.0000
205.0303
150.0000
210.0000