結果

問題 No.198 キャンディー・ボックス2
ユーザー kichirb3kichirb3
提出日時 2018-03-29 13:18:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 34 ms / 1,000 ms
コード長 604 bytes
コンパイル時間 117 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 10,508 KB
最終ジャッジ日時 2023-08-10 08:36:59
合計ジャッジ時間 2,533 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,396 KB
testcase_01 AC 33 ms
10,240 KB
testcase_02 AC 33 ms
10,488 KB
testcase_03 AC 32 ms
10,268 KB
testcase_04 AC 33 ms
10,444 KB
testcase_05 AC 33 ms
10,440 KB
testcase_06 AC 33 ms
10,292 KB
testcase_07 AC 32 ms
10,468 KB
testcase_08 AC 34 ms
10,456 KB
testcase_09 AC 34 ms
10,384 KB
testcase_10 AC 34 ms
10,444 KB
testcase_11 AC 34 ms
10,272 KB
testcase_12 AC 33 ms
10,388 KB
testcase_13 AC 33 ms
10,456 KB
testcase_14 AC 32 ms
10,300 KB
testcase_15 AC 32 ms
10,200 KB
testcase_16 AC 32 ms
10,196 KB
testcase_17 AC 33 ms
10,384 KB
testcase_18 AC 33 ms
10,288 KB
testcase_19 AC 33 ms
10,508 KB
testcase_20 AC 32 ms
10,216 KB
testcase_21 AC 33 ms
10,444 KB
testcase_22 AC 33 ms
10,308 KB
testcase_23 AC 33 ms
10,248 KB
testcase_24 AC 34 ms
10,272 KB
testcase_25 AC 34 ms
10,428 KB
testcase_26 AC 33 ms
10,388 KB
testcase_27 AC 33 ms
10,196 KB
testcase_28 AC 34 ms
10,460 KB
testcase_29 AC 33 ms
10,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
"""
No.198 キャンディー・ボックス2
https://yukicoder.me/problems/no/198

"""
import sys
from sys import stdin
from statistics import median
input = stdin.readline


def solve(B, N, candies):
    candies.sort()
    m = int(median(candies))
    max_avg = (sum(candies) + B) // N
    m = min(m, max_avg)

    res = [abs(x - m) for x in candies]
    return sum(res)


def main(args):
    B = int(input())
    N = int(input())
    candies = [int(input()) for _ in range(N)]
    ans = solve(B, N, candies)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
0