# Problem Link:

# Difficulty:

Easy

# Pre-requisites:

Probability

# Problem:

In a game between team A and team B, you are given the probability that team A will win. If you bet M rupees on team X, and team X wins, then you gain 2 * (1-P_{X}) * M rupees, whereas if team X loses, then you lose this M rupees. Starting out with 10000 rupees, what is the expected maximum value you can have, if you place your bets optimally?

# Explanation:

We are given P_{A}, and P_{B} (= 1-P_{A}). Let us bet M rupees on A and N rupees on B. Then, the expected gain/loss we will have is:

P_{A} * (Payoff for team A winning) + P_{B} * (Payoff for team B winning)

= P_{A} * (2 * P_{B} * M - N) + P_{B} * (2 * P_{A} * N - M)

= M * P_{B} * (2 * P_{A} - 1) + N * P_{A} * (2 * P_{B} - 1).

Note that, M * P_{B} >= 0, and N * P_{A} >= 0. Therefore, if P_{A} > 1/2, the above is monotonically increasing in M, and decreasing in N. Thus, it is best if we bet M = 10000, and N = 0 in this case. If P_{A} < 1/2, we have it monotonically decreasing in M, and increasing in N. Thus, in this case, it is best we bet M = 0, N = 10000.

Thus, final answer is as follows:

```
f(PA):
if(PA >= 0.5):
return 10000 + 10000 * (1 - PA) * (2 * PA - 1)
else:
return 10000 + 10000 * PA * (1 - 2 * PA)
```

# Setter’s Solution:

Will be updated soon.

# Tester’s Solution:

Can be found here