CF571B.Minimization

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You've got array AA , consisting of nn integers and a positive integer kk . Array AA is indexed by integers from 11 to nn .

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.

输入格式

The first line contains two integers n,kn,k ( 2<=n<=31052<=n<=3·10^{5} , 1<=k<=min(5000,n1)1<=k<=min(5000,n-1) ).

The second line contains nn integers A[1],A[2],...,A[n]A[1],A[2],...,A[n] ( 109<=A[i]<=109-10^{9}<=A[i]<=10^{9} ), separate by spaces — elements of the array AA .

输出格式

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
    

说明/提示

In the first test one of the optimal permutations is 1 4 21 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 52 3 4 4 3 5 .

首页