记录编号 |
22538 |
评测结果 |
AAAAAAAAAA |
题目名称 |
象棋比赛 |
最终得分 |
100 |
用户昵称 |
sr-end |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.102 s |
提交时间 |
2010-11-19 16:02:16 |
内存使用 |
0.69 MiB |
显示代码纯文本
program aa;
var
f,f1:text;
n,k,i,j,l:longint;
a:array[1..100000] of longint;
br:array[1..100000] of integer;
procedure Sort(l, r: longint);
var
i, j, x, y: longint;
begin
i := l; j := r; x := a[(l+r) DIV 2];
repeat
while a[i] < x do i := i + 1;
while x < a[j] do j := j - 1;
if i <= j then
begin
y := a[i]; a[i] := a[j]; a[j] := y;
i := i + 1; j := j - 1;
end;
until i > j;
if l < j then Sort(l, j);
if i < r then Sort(i, r);
end;
procedure Sortt(l, r: longint);
var
i, j, x, y: longint;
begin
i := l; j := r; x := br[(l+r) DIV 2];
repeat
while br[i] < x do i := i + 1;
while x < br[j] do j := j - 1;
if i <= j then
begin
y := br[i]; br[i] := br[j]; br[j] := y;
i := i + 1; j := j - 1;
end;
until i > j;
if l < j then Sortt(l, j);
if i < r then Sortt(i, r);
end;
begin
l:=0;
assign(f,'chess.in');assign(f1,'chess.out');
reset(f);rewrite(f1);
readln(f,n,k);
for i:=1 to n do
readln(f,a[i]);
sort(1,n);
for i:=1 to n-1 do
br[i]:=a[i+1]-a[i];
sortt(1,n-1);
for i:=1 to k do
l:=l+br[i];
write(f1,l);
close(f);close(f1);
end.