#P8664. [蓝桥杯 2018 省 A] 付账问题

[蓝桥杯 2018 省 A] 付账问题

Description

It is common for several people to go out for a meal together. But when it is time to pay the bill, disputes often arise.

Now there are nn people dining out, and their total spending is SS yuan. The ii-th person brought aia_i yuan. Fortunately, the total amount of money everyone brought is enough to pay the bill, but the question is: how much should each person pay?

To be fair, under the condition that the total amount paid is exactly SS, we want the standard deviation of the amounts each person pays to be as small as possible. Here we agree that the amount each person pays can be any non-negative real number, i.e., it does not have to be an integer multiple of 1 cent. You need to output the minimum possible standard deviation.

Introduction to standard deviation: standard deviation is the square root of the average of the squared differences between several numbers and their mean, and it is generally used to describe “how large the deviation is” among these numbers. Formally, let the amount paid by the ii-th person be bib_i yuan, then the standard deviation is $s=\sqrt{\frac{1}{n}\sum_{i=1}^n(b_i-\frac{1}{n}\sum_{i=1}^n b_i)}$.

Input Format

The first line contains two integers nn and SS.

The second line contains nn non-negative integers a1,,ana_1,\cdots,a_n.

Output Format

Output to standard output.

Output the minimum standard deviation, rounded to 44 decimal places.

It is guaranteed that adding or subtracting 10910^{-9} to the correct answer will not change the rounding result.

5 2333
666 666 666 666 666
0.0000
10 30
2 1 4 7 4 8 3 6 4 7
0.7928

Hint

Sample Explanation

  1. Everyone pays 2333/52333/5 yuan, and the standard deviation is 0.

Data Specification

For 10%10\% of the testdata, all aia_i are equal.

For 30%30\% of the testdata, all non-zero aia_i are equal.

For 60%60\% of the testdata, n1000n \le 1000.

For 80%80\% of the testdata, n105n \le 10^5.

For all testdata, n5×105n \le 5 \times 10^5 and 0ai1090 \le a_i \le 10^9.

Translated by ChatGPT 5