比赛 20101119 评测结果 C
题目名称 象棋比赛 最终得分 0
用户昵称 DeiTy 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-19 10:30:03
显示代码纯文本
program chess;
var
   n,k,i,j,t,sum:longint;
   a,cha:array[1..10000] of longint;
begin
  assign(input,'chess.in');
  assign(output,'chess.out');
  reset(input);
  rewrite(output);
  readln(n,k);
  for i:=1 to n do readln(a[i]);
  for i:=1 to n-1 do
    for j:=i+1 to n do
       if a[i]>a[j] then begin
                           t:=a[i];
                           a[i]:=a[j];
                           a[j]:=t;
                         end;
  for i:=1 to n-1 do cha[i]:=a[i+1]-a[i];
  for i:=1 to n-2 do
   for j:=i+1 to n-1 do
     if cha[i]>cha[j] then begin
                             t:=cha[i];
                             cha[i]:=cha[j];
                             cha[j]:=t;
                           end;
  for i:=1 to k do sum:=sum+cha[i];
  writeln(sum);
  close(input);
  close(output);
end.
end.