| 比赛 | 20101119 | 评测结果 | AAAAAAAAAA | 
    | 题目名称 | 象棋比赛 | 最终得分 | 100 | 
    | 用户昵称 | lc | 运行时间 | 0.000 s | 
    | 代码语言 | C++ | 内存使用 | 0.00 MiB | 
    | 提交时间 | 2010-11-19 10:08:12 | 
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int maxn = 100010;
int num[maxn],tmp[maxn];
int N,K,Ans;
bool cmp(const int a,const int b)
{
	return a < b;
}
void prep()
{
	scanf("%d%d",&N,&K);
	for (int i=1; i<=N; i++) scanf("%d",&num[i]);
	sort(num+1,num+1+N,cmp);
}
void work()
{
	for (int i=1; i<N; i++) tmp[i] = num[i+1] - num[i];
	sort(tmp+1,tmp+1+N-1,cmp);
	for (int i=1; i<=K; i++) Ans += tmp[i];
	printf("%d\n",Ans);
}
int main()
{
	freopen("chess.in","r",stdin);
	freopen("chess.out","w",stdout);
	prep();
	work();
	return 0;
}