atcoder#ABC224G. [ABC224G] Roll or Increment
[ABC224G] Roll or Increment
Score : points
Problem Statement
We have a -face die (singular of dice) that shows integers from through with equal probability. Below, the die is said to be showing an integer when it is placed so that the top face is the face with the integer . Initially, the die shows the integer .
You can do the following two operations on this die any number (possibly zero) of times in any order.
- Pay yen (the Japanese currency) to "increase" the value shown by the die by , that is, reposition it to show when it currently shows . This operation cannot be done when the die shows .
- Pay yen to recast the die, after which it will show an integer between and with equal probability.
Consider making the die show from the initial state where it shows . Print the minimum expected value of the cost required to do so when the optimal strategy is used to minimize this expected value.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer. Your output will be considered correct when its absolute or relative error is at most .
5 2 4 10 4
15.0000000000000000
When the optimal strategy is used to minimize the expected cost, it will be yen.
10 6 6 1 2
0.0000000000000000
The die already shows in the initial state, which means no operation is needed.
1000000000 1000000000 1 1000000000 1000000000
1000000000000000000.0000000000000000
Your output will be considered correct when its absolute or relative error is at most .