結果
問題 | No.615 集合に分けよう |
ユーザー |
|
提出日時 | 2017-12-16 11:06:10 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 860 bytes |
コンパイル時間 | 767 ms |
コンパイル使用メモリ | 113,844 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-12 23:09:20 |
合計ジャッジ時間 | 1,795 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 26 |
ソースコード
import std.stdio, std.string, std.conv, std.algorithm, std.numeric; import std.range, std.array, std.math, std.typecons, std.container, core.bitop; void main() { int n, k; scan(n, k); auto a = readln.split.to!(long[]); a.sort(); auto d = new long[](n-1); foreach (i ; 0 .. n - 1) { d[i] = a[i+1] - a[i]; } d.sort(); long ans; foreach (i ; 0 .. n - k) { ans += d[i]; } writeln(ans); } void scan(T...)(ref T args) { string[] line = readln.split; foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }