結果

問題 No.615 集合に分けよう
ユーザー te-shte-sh
提出日時 2017-12-15 00:15:58
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 385 bytes
コンパイル時間 749 ms
コンパイル使用メモリ 95,800 KB
実行使用メモリ 6,240 KB
最終ジャッジ日時 2023-09-03 17:36:55
合計ジャッジ時間 2,948 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 26 ms
5,580 KB
testcase_17 AC 20 ms
5,896 KB
testcase_18 AC 26 ms
6,032 KB
testcase_19 AC 26 ms
5,516 KB
testcase_20 AC 26 ms
6,240 KB
testcase_21 AC 26 ms
5,812 KB
testcase_22 AC 25 ms
5,452 KB
testcase_23 AC 10 ms
5,364 KB
testcase_24 AC 24 ms
6,232 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 6 ms
4,840 KB
testcase_28 AC 7 ms
5,628 KB
testcase_29 AC 15 ms
5,916 KB
testcase_30 AC 15 ms
5,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd = readln.split.to!(int[]), n = rd[0], k = rd[1];
  auto a = readln.split.to!(long[]);
  a.sort();

  if (k == 1) {
    writeln(a[n-1] - a[0]);
    return;
  }

  auto b = new long[](n-1);
  foreach (i; 0..n-1) b[i] = a[i+1]-a[i];

  b.sort!"a > b";

  writeln(a[n-1] - a[0] - b[0..k-1].sum);
}
0