#P8664. Fair Payment Distribution

    ID: 21830 Type: Default 1000ms 256MiB

Fair Payment Distribution

Fair Payment Distribution

A group of n people go out for a meal and the total bill is S yuan. The i-th person has a_i yuan on hand. It is guaranteed that \(\sum_{i=1}^n a_i \ge S\). Each person will pay an amount \(b_i\) (which can be any nonnegative real number, not necessarily an integral multiple of 0.01) such that \(\sum_{i=1}^n b_i = S\) and \(b_i \le a_i\) (since one cannot pay more than one has).

To be fair, the standard deviation of the amounts paid is minimized. The standard deviation is defined as \[ s = \sqrt{\frac{1}{n}\sum_{i=1}^n \Big(b_i - \frac{S}{n}\Big)^2 }. \]

Your task is to compute the minimum possible standard deviation under these constraints.

Note: To achieve the minimum standard deviation, one should try to make the payments as equal as possible. In an ideal scenario, every person would pay \(\frac{S}{n}\) and the standard deviation would be 0. However, if for some person \(a_i < \frac{S}{n}\), that person cannot pay the ideal share. In this case, set \(b_i = a_i\) for those individuals and distribute the remaining amount evenly among the others (without exceeding their \(a_i\)). This water-filling approach guarantees that the deviation \(|b_i-\frac{S}{n}|\) is minimized.

inputFormat

The first line contains two numbers n and S (\(1 \le n \le 10^5\), \(0 \le S \le 10^{12}\)). The second line contains n numbers a1, a2, \dots, an (\(0 \le a_i \le 10^{12}\)), which represent the money each person has. It is guaranteed that \(\sum_{i=1}^n a_i \ge S\).

outputFormat

Output the minimum standard deviation. Answers within an absolute or relative error of \(10^{-6}\) will be accepted.

sample

3 15
10 10 10
0.0000000000

</p>