結果

問題 No.198 キャンディー・ボックス2
ユーザー te-sh
提出日時 2016-09-15 14:23:16
言語 D
(dmd 2.109.1)
結果
WA  
実行時間 -
コード長 589 bytes
コンパイル時間 783 ms
コンパイル使用メモリ 123,056 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-12 04:23:52
合計ジャッジ時間 1,743 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 10 WA * 10 RE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;

void main()
{
  auto b = readln.chomp.to!int;
  auto n = readln.chomp.to!size_t;
  auto ci = iota(n).map!(_ => readln.chomp.to!int).array;

  auto maxR = (ci.sum + b) / n;

  int calc(int r) { return ci.map!(c => (c - r).abs).sum; }

  auto s = iota(maxR + 1)
    .map!(r => calc((r + 1).to!int) - calc(r.to!int))
    .assumeSorted.lowerBound(0);

  writeln(calc(s.length.to!int));
}
0