結果

問題 No.198 キャンディー・ボックス2
コンテスト
ユーザー koheijkt
提出日時 2025-09-10 17:59:54
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 529 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 236 ms
コンパイル使用メモリ 96,360 KB
実行使用メモリ 79,232 KB
最終ジャッジ日時 2026-07-14 23:43:50
合計ジャッジ時間 3,903 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

B = int(input())
N = int(input())
C = [int(input()) for _ in range(N)]
C.sort()
SUM = sum(C)

rui = [0]
for c in C:
    rui.append(rui[-1] + c)

ansl = []
for i in range(N):
    target = C[i]
    temochi = B

    # 左には i 個いる
    temochi -= target * i - rui[i]

    # 右には N - 1 - i 個いる
    temochi += (SUM - rui[i + 1]) - target * (N - i - 1)

    if temochi >= 0:
        ans = 0
        for i in range(N):
            c = C[i]
            ans += abs(c - target)
        ansl.append(ans)

print(min(ansl))
0