题库练习 Minimization
← 上一题 下一题 →

A10047 | Minimization

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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

![](/uploads/acgo/image/b742d134b38ecc71_96b2c689a323.jpeg) became minimal possible. In particular, it is allowed not to change order of elements at all.

输入格式

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$ .

输出格式

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

输入输出样例

输入 #1
3 2
1 2 4
输出 #1
1
输入 #2
5 2
3 -5 3 -5 3
输出 #2
0
输入 #3
6 3
4 3 4 3 2 5
输出 #3
3
C++ 编辑器
输入
输出