Codeforces Round 317 [AimFund Thanks-Round] (Div. 1)
B
Minimization
Codeforces
2000
原题
← AC →
翻译中…

You've got array $*A*$, consisting of $*n*$ integers and a positive integer $*k*$. Array $*A*$ is indexed by integers from $1$ to $*n*$.

翻译中…

You need to permute the array elements so that value

翻译中…

image

翻译中…

became minimal possible. In particular, it is allowed not to change order of elements at all.

翻译中…

Input

翻译中…

The first line contains two integers $*n*, *k*$ ($2 ≤ *n* ≤ 3·10^{5}$, $1 ≤ *k* ≤ *min*(5000, *n* - 1)$).

翻译中…

The second line contains $*n*$ integers $*A*[1], *A*[2], ..., *A*[*n*]$ ($- 10^{9} ≤ *A*[*i*] ≤ 10^{9}$), separate by spaces — elements of the array $*A*$.

翻译中…

Output

翻译中…

Print the minimum possible value of the sum described in the statement.

翻译中…

Note

翻译中…

In the first test one of the optimal permutations is $1 4 2$.

翻译中…

In the second test the initial order is optimal.

翻译中…

In the third test one of the optimal permutations is $2 3 4 4 3 5$.

翻译中…

样例

Input #1
3 2
1 2 4
Output #1
1
InputCopy OutputCopy
Input #2
5 2
3 -5 3 -5 3
Output #2
0
InputCopy OutputCopy
Input #3
6 3
4 3 4 3 2 5
Output #3
3
InputCopy OutputCopy
题目信息
题号
571B
时间限制
2 s
内存限制
256 MB
标签
动态规划
贪心
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。