#P10616. Maximum Expected Profit with Loss Refund

    ID: 12641 Type: Default 1000ms 256MiB

Maximum Expected Profit with Loss Refund

Maximum Expected Profit with Loss Refund

Casinos sometimes offer gamblers a special deal: you can bet as much as you want, and after you finish, if you are losing money relative to your starting amount, the casino will refund you x% of your losses. If you are ahead, you keep all of your winnings. In this problem, every bet costs $1 and pays out $2. That is, a win earns you a net profit of $+1$, and a loss costs you $1$. However, if you end with a negative net profit, the casino will return \(x\%\) of your losses so that your final profit becomes

[ \text{profit} = \begin{cases} z, & \text{if } z \ge 0,\ z + \frac{x}{100} \cdot (-z) = z\left(1-\frac{x}{100}\right), & \text{if } z < 0, \end{cases} ]

where \(z\) is your net profit before refund.

You are given two numbers:

  • x: the refund percentage; and
  • p: the percentage probability of winning a single bet.

You may choose any strategy (the order and number of bets) to maximize your expected profit. Note that there is no time or money limit, but you can redeem the refund offer only once at the end. For instance, if \(x=20\) (i.e. refund is 20%) and you make 10 bets, then:

  • If 3 bets win, your raw net profit is \(3 - 7 = -4\). With a 20% refund on the loss, your final profit becomes \(-4 + 0.2 \times 4 = -3.2\) dollars.
  • If 6 bets win, your net profit is \(6 - 4 = +2\) dollars and you keep all winnings.

Assuming each bet is independent, a win yields +1 and a loss yields \(-\left(1-\frac{x}{100}\right)\) (if you stop immediately after the bet), the expected profit from a single bet is

[ E = \frac{p}{100} \times 1 + \left(1-\frac{p}{100}\right) \times \left(-\left(1-\frac{x}{100}\right)\right) = \frac{p}{100} - \left(1-\frac{p}{100}\right)\left(1-\frac{x}{100}\right). ]

Your goal is to compute the maximum expected profit you can achieve by choosing an optimal gambling strategy.

Note:

  • If the expected profit per bet is positive and because you can bet indefinitely, the maximum expected profit is infinite. In such a case, output Infinity (case-sensitive).
  • If it is not beneficial to bet, the best you can do is to not bet at all (i.e. profit = 0).

inputFormat

The input consists of a single line with two numbers:

  • x (an integer, \(0 \le x \le 100\)) representing the refund percentage.
  • p (a real number, \(0 \le p \le 100\)) representing the winning probability in percentage.

They are separated by spaces.

outputFormat

Output the maximum expected profit. If the optimal expected profit is infinite, output Infinity. Otherwise, output a real number. The answer will be accepted if its absolute or relative error is within \(10^{-6}\).

sample

20 50
0.1

</p>