結果

問題 No.615 集合に分けよう
ユーザー ikdikd
提出日時 2017-12-16 00:01:22
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 560 bytes
コンパイル時間 673 ms
コンパイル使用メモリ 107,092 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-12 23:09:04
合計ジャッジ時間 1,887 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.typecons;

  int n, k; rd(n, k);
  auto a=readln.split.to!(long[]);

  sort(a);
  auto dif=new long[](n-1);
  foreach(i; 0..(n-1)) dif[i]=a[i+1]-a[i];
  sort(dif);
  writeln(sum(dif[0..(n-k)], 0L));
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
void wr(T...)(T x){
  import std.stdio;
  foreach(e; x) stderr.write(e, " ");
  stderr.writeln();
}
0