#P2503. [HAOI2006] 均分数据

    ID: 1517 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>模拟贪心2006河南各省省选模拟退火

[HAOI2006] 均分数据

Description

Given nn positive integers a1,a2...ana_1,a_2 ... a_n. We want to partition them into mm groups so that the sums of the groups are as balanced as possible, i.e., the standard deviation of the group sums is minimized. The formula for the standard deviation is as follows:

$$\sigma = \sqrt{\frac 1m \sum\limits_{i=1}^m(\overline x - x_i)^2},\overline x = \frac 1m \sum\limits_{i=1}^m x_i$$

Here, σ\sigma is the standard deviation, xˉ\bar{x} is the average of the group sums, and xix_i is the sum of the ii-th group.

Input Format

The first line contains two integers, representing the values of n,mn,m (nn is the number of integers, and mm is the number of groups).

The second line contains nn integers, representing a1,a2...ana_1,a_2 ... a_n. Each integer is in the range [1,50][1,50].

Integers on the same line are separated by spaces.

Output Format

Output one real number on a single line, representing the minimal value of the standard deviation, rounded to two decimal places.

6 3
1 2 3 4 5 6

0.00

Hint

Sample explanation: group as (1,6)(1,6), (2,5)(2,5), (3,4)(3,4).

Constraints

For 40%40\% of the testdata, it is guaranteed that mn10m \le n \le 10, 2m62 \le m \le 6.

For 100%100\% of the testdata, it is guaranteed that mn20m \le n \le 20, 2m62 \le m \le 6.

Translated by ChatGPT 5