记录编号 |
81411 |
评测结果 |
AAAAAAAAAA |
题目名称 |
象棋比赛 |
最终得分 |
100 |
用户昵称 |
TA |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.041 s |
提交时间 |
2013-11-13 12:11:37 |
内存使用 |
0.09 MiB |
显示代码纯文本
var
n,k,i,j,h,ans,x:longint;
a,r:array[1..100000] of longint;
procedure merge(s,m,t:longint);
var
i,j,k:longint;
begin
i:=s;
j:=m+1;
k:=s;
while (i<=m) and (j<=t) do
begin
if a[i]<=a[j] then
begin
r[k]:=a[i];
inc(i);
end
else
begin
r[k]:=a[j];
inc(j);
end;
inc(k);
end;
while i<=m do
begin
r[k]:=a[i];
inc(i);
inc(k);
end;
while j<=t do
begin
r[k]:=a[j];
inc(j);
inc(k);
end;
for i:=s to t do
a[i]:=r[i];
end;
procedure sort(s,t:longint);
var
m:longint;
begin
if s<t then
begin
m:=(s+t) div 2;
sort(s,m);
sort(m+1,t);
merge(s,m,t);
end;
end;
begin
assign(input,'chess.in');
assign(output,'chess.out');
reset(input);
rewrite(output);
//while not(eof) do
//begin
readln(n,k);
for i:=1 to n do
readln(a[i]);
sort(1,n);
for i:=1 to n-1 do
a[i]:=a[i+1]-a[i];
sort(1,n-1);
ans:=0;
for i:=1 to k do
inc(ans,a[i]);
writeln(ans);
//end;
close(input);
close(output);
end.