跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F1588. Minimization

    ID: 1594 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划贪心排序算法思想编程与模拟提高难度共享题库Codeforces英文题面题目来源题面语言

Minimization

题目描述

B. Minimization
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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

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·105, 1≤kmin(5000,n-1)).

The second line contains n integers A[1],A[2],...,A[n] (-109A[i]≤109), separate by spaces − elements of the array A.

Output

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

Examples
Input
3 2
1 2 4
Output
1
Input
5 2
3 -5 3 -5 3
Output
0
Input
6 3
4 3 4 3 2 5
Output
3
Note

In the first test one of the optimal permutations is 142.

In the second test the initial order is optimal.

In the third test one of the optimal permutations is 234435.


题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 1111 题。保留原作者与原赛事署名。