結果

問題 No.198 キャンディー・ボックス2
ユーザー 👑 hiragnhiragn
提出日時 2022-11-19 00:13:27
言語 Python3
(3.10.1 + numpy 1.22.3 + scipy 1.8.0)
結果
AC  
実行時間 133 ms / 1,000 ms
コード長 431 bytes
コンパイル時間 60 ms
使用メモリ 28,880 KB
最終ジャッジ日時 2023-03-28 14:40:43
合計ジャッジ時間 5,577 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 128 ms
28,748 KB
testcase_01 AC 128 ms
28,780 KB
testcase_02 AC 128 ms
28,620 KB
testcase_03 AC 128 ms
28,528 KB
testcase_04 AC 132 ms
28,748 KB
testcase_05 AC 131 ms
28,544 KB
testcase_06 AC 131 ms
28,552 KB
testcase_07 AC 130 ms
28,764 KB
testcase_08 AC 132 ms
28,744 KB
testcase_09 AC 131 ms
28,620 KB
testcase_10 AC 130 ms
28,624 KB
testcase_11 AC 130 ms
28,792 KB
testcase_12 AC 130 ms
28,648 KB
testcase_13 AC 131 ms
28,880 KB
testcase_14 AC 132 ms
28,684 KB
testcase_15 AC 131 ms
28,484 KB
testcase_16 AC 132 ms
28,528 KB
testcase_17 AC 131 ms
28,804 KB
testcase_18 AC 131 ms
28,656 KB
testcase_19 AC 131 ms
28,836 KB
testcase_20 AC 131 ms
28,584 KB
testcase_21 AC 131 ms
28,788 KB
testcase_22 AC 131 ms
28,596 KB
testcase_23 AC 132 ms
28,684 KB
testcase_24 AC 133 ms
28,592 KB
testcase_25 AC 132 ms
28,772 KB
testcase_26 AC 132 ms
28,524 KB
testcase_27 AC 129 ms
28,780 KB
testcase_28 AC 132 ms
28,752 KB
testcase_29 AC 132 ms
28,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np


def main():
    b = int(input())
    n = int(input())
    c = np.array([int(input()) for _ in range(n)], dtype='int64')

    # bが小さいと中央値np.median(c)を実現できない。
    # n * x = sum(c) + bをみたすxと中央値の小さい方を作る
    x = min(int(np.median(c)), (np.sum(c) + b) // n)
    ans = sum([abs(i - x) for i in c])
    print(ans)


if __name__ == "__main__":
    main()
0