#P9627. Optimal Firework Production Strategy

    ID: 22774 Type: Default 1000ms 256MiB

Optimal Firework Production Strategy

Optimal Firework Production Strategy

Kotori is preparing for the upcoming hanabi taikai1 by making fireworks. It takes her n minutes to make a single firework. However, since she is not very skilled, each firework has a probability of p×10-4 to be perfect.

After finishing a firework, she can immediately start making the next one or spend m minutes lighting all the fireworks produced so far. If at least one of the lit fireworks is perfect, she will be happy and go to rest. Otherwise, she continues the practice. Your task is to determine the minimum expected practicing time, in minutes, before she goes to rest, assuming she follows the optimal strategy.

Note: Regardless of the number of fireworks, lighting them always takes exactly m minutes.

1. Hanabi taikai: Romaji of the Japanese word “花火大會”, meaning the firework (or party) event.

The optimal strategy is to decide on a number K (where K ≥ 1) of fireworks to produce before lighting them all at once. The probability that at least one of these K fireworks is perfect is given by

[ F(K)=1-(1-p\times10^{-4})^K, ]

and the time spent in one trial is K×n + m. If the trial fails (i.e. no perfect firework), the process repeats. Thus, the expected total practicing time is

[ E(K)=\frac{K\times n + m}{1-(1-p\times10^{-4})^K}. ]

Your task is to choose an integer K (with K ≥ 1) that minimizes E(K) and output the corresponding minimal expected time.

inputFormat

The input consists of a single line containing three integers:

  • n (the minutes required to produce one firework),
  • m (the minutes required to light the fireworks),
  • p (used to compute the perfection probability as p×10-4).

Constraints: All input values are positive integers.

outputFormat

Output a single real number, the minimum expected practicing time (in minutes) before Kotori goes to rest. Your answer will be accepted if its absolute or relative error does not exceed 10-6.

sample

1 1 5000
4.0000000000