比赛 20101119 评测结果 AAAAAAAAAA
题目名称 象棋比赛 最终得分 100
用户昵称 ZhouZn1 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-19 08:52:06
显示代码纯文本
program zzn;
type
        arr=array[1..100000]of longint;
var
        n,i,j,k,ans:longint;
        a,b:arr;
procedure init;
begin
        assign(input,'chess.in');
        reset(input);
        assign(output,'chess.out');
        rewrite(output);
        readln(n,k);
        for i:=1 to n do readln(a[i]);
end;
procedure closef;
begin
        close(input);
        close(output);
end;
procedure swap(var a,b:longint);
var
        t:longint;
begin
        t:=a;
        a:=b;
        b:=t;
end;
procedure qsort(var a:arr;l,r:longint);
var
        k,i,j:longint;
begin
        i:=l;j:=r;
        k:=a[(i+j)shr 1];
        repeat
         while a[i]<k do inc(i);
         while a[j]>k do dec(j);
         if i<=j then
          begin
              swap(a[i],a[j]);
              inc(i);
              dec(j);
          end;
        until i>=j;
        if i<r then qsort(a,i,r);
        if j>l then qsort(a,l,j);
end;
procedure main;
begin
        qsort(a,1,n);
        for i:=2 to n do
        b[i-1]:=a[i]-a[i-1];
        qsort(b,1,n-1);
        ans:=0;
        for i:=1 to k do inc(ans,b[i]);
        writeln(ans);
end;
begin
        init;
        main;
        closef;
end.