//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
typedef long long ll;
#define endl '\n'
using namespace std;
const int N=200010;
const int K=410;
ll val[N/K][K];
ll dp[K][K];
const ll inf=1000000000000000001ll;
int L[N/K],R[N/K];
ll a[N];
ll dp1[2][K];
void solve(){
int n,k;cin>>n>>k;
for (int i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+n+1);
int m=(n+K-1)/K;
for (int it=1;it<=m;it++){
L[it]=(it-1)*K+1;
R[it]=min(n,it*K);
int len=R[it]-L[it]+1;
for (int j=0;j<=len;j++){
for (int t=0;t<=len;t++){
dp[j][t]=inf;
}
}
dp[0][0]=0ll;
for (int i=1;i<=len;i++){
for (int j=1;j*2<=len;j++){
if (i>1) dp[i][j]=min(dp[i-1][j],dp[i-2][j-1]+a[i+L[it]-1]-a[i+L[it]-2]);
else dp[i][j]=dp[i-1][j];
// cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
}
}
for (int i=0;i<K;i++){
if (i*2<=len) val[it][i]=dp[len][i];
else val[it][i]=inf;
}
}
for (int i=0;i<2;i++){
for (int j=0;j<=m;j++){
dp[i][j]=inf;
}
}
dp[0][0]=0ll;
for (int i=1;i<=k;++i){
for (int j=1;j<=m;++){
int len=R[j]-L[j]+1;
}
}
cout<<val[m][k]<<endl;
//3 1 5 18 34 1 1 3 4
//dp[i][j]
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int tt=1;
while (tt--){
solve();
}
return 0;
}