QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 128 MB Puntuación total: 100

#7497. Calabash Brothers Save Grandpa

Estadísticas

There are $n$ Calabash Brothers. The $i$-th brother has a combat power of $p_i$ and is born on the morning of the $i$-th day. It is guaranteed that the sum of all $p_i$ is $1$.

On the evening of the $i$-th day, the brothers who have already been born can choose to either accumulate their strength (wait until the next day) or have everyone set out to rescue their grandfather. If the total combat power of these brothers is $P$, there is a probability of $P$ to rescue their grandfather and a probability of $1-P$ to fail. If they fail, all brothers who participated in the rescue will be captured by the demon and cannot participate in any future rescue attempts.

However, the demon decides the fate of the grandfather using a Russian roulette method. That is, the demon first uniformly generates a random integer $x$ between $1$ and $n$, and then kills the grandfather at noon on the $x$-th day. If the grandfather has already been killed, the rescue attempt by the brothers naturally fails. The brothers do not know the value of $x$.

Please help calculate the strategy the brothers should follow to maximize the probability of successfully rescuing their grandfather.

Input

The first line contains a positive integer $n$.

The next line contains $n$ decimal numbers $p_i$.

Output

Output a decimal number representing the probability of successfully rescuing the grandfather under the optimal strategy. Your answer will be considered correct if the error does not exceed $10^{-6}$.

Examples

Input 1

1
1

Output 1

0

Input 2

7
0.5 0.5 0 0 0 0 0

Output 2

0.71428571428571430157

Note 2

The optimal strategy is for the two brothers to rescue together on the second day. In this case, if the grandfather has not been killed yet, the rescue is guaranteed to succeed.

The probability of a successful rescue is $5/7$.

Input 3

7
0.537354 0.277078 0.124580 0.046589 0.012498 0.001853 0.000048

Output 3

0.59878460205905026381

Constraints

For $30\%$ of the data, $n \leq 3$.

For $60\%$ of the data, $n \leq 15$.

For $100\%$ of the data, $n \leq 1000$.

It is guaranteed that $\sum p_i = 1$ and the decimal numbers have at most $6$ decimal places.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.