#P9138. The Lighthouse Watchmen Fueling Game
The Lighthouse Watchmen Fueling Game
The Lighthouse Watchmen Fueling Game
On a rocky coastline stands a gray‐white lighthouse. Before electric light, kerosene lamps guided ships. To refuel the lighthouse the watchmen perform a curious game. There are two watchmen, named Y and S. Every time the lighthouse is refueled, both watchmen each bring a bucket of capacity \(L\). The lighthouse has \(N\) containers, with the \(i\)th container holding \(a_i\) units of kerosene. When it is a watchman’s turn to refuel, that person performs as many operations as he wishes (possibly zero) according to the following procedure:
- The acting watchman randomly selects one of the \(N\) containers with equal probability.
- The selected container is filled to its full capacity \(a_i\) (its volume), and all of its kerosene is poured into the other watchman’s bucket.
However, if at some turn the chosen container would cause the opponent's bucket to become full and there is excess kerosene left in the container (i.e. if the current amount plus \(a_i\) would exceed \(L\) while not using the whole container because only \(L - (\text{current})\) is needed), then the acting watchman loses the round by being forced to carry both buckets. (In our formulation, this is an extra heavy penalty.)
The order is as follows: First the first mover (who we call first) takes his turn to add kerosene to the other watchman’s bucket. After he finishes, the second mover takes his turn. After both turns the two compare the fullness of the buckets they filled for the opponent (i.e. the first mover has filled watchman S’s bucket and the second mover has filled watchman Y’s bucket). Then, each carries his own bucket to the lamp room. Each watchman wants the other to carry as much kerosene as possible relative to his own load.
Both watchmen can perform the fueling operation as many times as they like but will stop before risking an overflow. In particular, note that a fueling operation is guaranteed to be safe only if the current amount in the bucket is at most \(L - \max\{a_i\}\) so that whatever container is chosen the bucket will not overflow. Under optimal play, the first mover will perform safe moves to maximize the fuel in the opponent's bucket, while the second mover will avoid fueling in order to keep his own bucket as empty as possible. (If an overflow occurs on a move by the first mover, he is penalized by having to carry both buckets.)
Your task is to compute, under the assumption that both players act optimally, the probability that the first mover's carried kerosene (i.e. the fuel in his own bucket, which is filled by his opponent in the second phase) is not more than the second mover's carried kerosene (i.e. the fuel in the other bucket filled by the first mover).
It can be shown that under optimal play the outcome is always in the first mover’s favor. In fact, the equilibrium strategy is as follows:
- If \(L \ge \max\{a_i\}\), then the first mover can safely perform at least one fueling move (since when his opponent's bucket is not too full every container is safe). He will continue until the bucket's fuel is high, but will stop before risking an overflow. Meanwhile, the second mover, wishing to avoid increasing his own bucket, will choose to do nothing.
- If \(L < \max\{a_i\}\), then fueling even once carries a risk, so both players will act conservatively and perform zero moves.
In either case the final outcome is such that the first mover’s own bucket is less than or equal to the opponent’s bucket. Therefore, the answer is always \(1\) (i.e. probability 1).
Note. All formulas are written in \(\LaTeX\) format.
inputFormat
The input consists of two lines.
The first line contains two integers \(N\) and \(L\) (1 ≤ \(N\) ≤ 105, 1 ≤ \(L\) ≤ 109) — the number of containers and the capacity of each bucket.
The second line contains \(N\) integers \(a_1, a_2, \ldots, a_N\) (1 ≤ \(a_i\) ≤ 109) where \(a_i\) is the capacity of the \(i\)th container.
outputFormat
Output a single real number: the probability that under optimal play the fuel carried by the first mover is not more than that carried by the second mover. It can be proved that the answer is always 1. Your output will be considered correct if its absolute or relative error does not exceed 10-6.
sample
3 10
1 2 3
1