問題一覧 > 通常問題

No.21 Difference of Averages

レベル : / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 996
作問者 : kroton
お気に入りにしたユーザー ProblemId : 67 / 自分の提出
問題文最終更新日: 2026-06-25 03:14:21
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
yukicoder contest 21 (順位表) の他の問題:

Problem Statement

You are given \(N\) numbers. Divide them into \(K(\geq 3)\) groups.
Each group must contain at least one number.

ex) For example, if the given numbers are \(\{10,3,23,91,5\}\) and \(K=3\), then
a division such as \(\{\{3,91\},\{23,5\},\{10\}\}\) is valid, while
a division such as \(\{\{\},\{3,5,10\},\{23,91\}\}\) is not allowed.

Compute the average of each group, then from these compute (largest average) - (smallest average),
and finally round the fractional part up; the resulting value is called the "difference of averages".
Find the difference of averages when the grouping is chosen so that the difference of averages is maximized.

Input

\(N\)
\(K\)
\(n_1\)
\(n_2\)
\(\dots\)
\(n_N\)

The \(1\)st line contains \(N\ (3 \leq N \leq 9)\).
The \(2\)nd line contains \(K\ (3 \leq K \leq N)\).
Lines \(3\) through \(N+2\) contain the numbers \((1 \leq n_i \leq 1000, 1 \leq i \leq N)\).

Output

Output the numerical answer as a string.
Print a newline at the end.

Sample

Sample 1
Input
5
3
555
20
432
301
21
Output
535

For example, if we group them as \(\{\{555\}, \{21,20\}, \{433,301\}\}\),
the averages are \(\{555/1, (21+20)/2, (432+301)/2\} = \{555, 20.5, 366.5\}\), so
(largest average) - (smallest average) is \(555-20.5 = 534.5\).
Finally, rounding the fractional part up gives \(535\).

Sample 2
Input
8
4
329
980
656
738
739
542
873
501
Output
651

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。