Expected Earnings

0

0 votes
Algorithms, Medium-Hard
Problem

You are playing a game with a bag of red and black balls. Initially, you are told that the bag has n balls total. In addition, you are also told that the bag has probability pi/106 of containing exactly i red balls.

You now would like to buy balls from this bag. You really like the color red, so red balls are worth a unit of 1, while black balls are worth nothing. To buy a ball, if there are still balls in the bag, you pay a cost c with 0c1, and draw a ball randomly from the bag. You can choose to stop buying at any point (and you can even choose to not buy anything at all).

Given that you buy optimally to maximize the expected profit (i.e. # red balls - cost needed to obtain them), print the maximum expected profit.

Input Format

The first line of input will contain two integers n,X.

The next line of input will contain n+1 integers p0,p1,pn.

The value of c can be computed as X106.

Output Format

Print a single floating point number representing the optimal expected value.

Your answer will be accepted if it has absolute or relative error at most 109. More specifically, if your answer is a and the jury answer is b, your answer will be accepted if |ab|max(1,b)109.

Constraint

1n10000

0X106

0pi106

ni=0pi=106

c can be computed as X/106

Sample Input
3 200000
250000 250000 250000 250000
Sample Output
0.9
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Here, there is equal probability for the bag to contain 0,1,2,3 red balls. Also, it costs 0.2 to draw a ball from the bag.

Editor Image

?