Problem list
Log in
#icpc00188 · ICPC NWERC 2017

Knockout Tournament

Gold I 2.0 s 2048 MB

Laura is organising a knockout tournament, in which her friend Dale takes part. Laura would like to maximise the probability of Dale winning the tournament by arranging the games in a favourable way. She does not know how to do it, so she asked you for help. Naturally, you refuse to cooperate with such a deplorable act—but then you realise that it is a very nice puzzle!

When the number of players is a power of two, the tournament setup can be described recursively as follows: the players are divided into two equal groups that each play their own knockout tournament, after which the winners of both tournaments play each other. Once a player loses, they are out of the tournament.

When the number of players is not a power of two, some of the last players in the starting line-up advance from the first round automatically so that in the second round the number of players left is a power of two, as shown in Figure .

Every player has a rating indicating their strength. A player with rating $a$ wins a game against a player with rating $b$ with probability $\frac{a}{a+b}$ (independently of any previous matches played).

Laura as the organiser can order the starting line-up of players in any way she likes. What is the maximum probability of Dale winning the tournament?

Input

The input consists of:

  • One line with an integer $n$ ($2 \le n \le 4096$), the total number of players.
  • $n$ lines, each with an integer $r$ ($1 \le r \le 10^5$), the rating of a player. The first rating given is Dale's rating.

Output

Output the maximum probability with which Dale can win the tournament given a favourable setup. Your answer should have an absolute or relative error of at most $10^{-6}$.

Example 1

Input
4
3
1
2
4
Output
0.364285714

Example 2

Input
5
1
1
3
3
3
Output
0.125
Source
ICPC NWERC 2017
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code