0
0
0
阿巴
资深守护
资深守护
#include<bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
int n,k,a[10005],b[10005],cnt,sum;
int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+n+1);
for(int i=2;i<=n;i++){
b[++cnt]=a[i]-a[i-1];
}
sort(b+1,b+cnt+1);
for(int i=1;i<=k;i++){
sum+=b[i];
}
cout<<sum;
//fclose(stdin);
//fclose(stdout);
return 0;
}
0
0
0
0
0