結果

問題 No.198 キャンディー・ボックス2
コンテスト
ユーザー convexineq
提出日時 2020-12-18 18:43:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 41 ms / 1,000 ms
コード長 263 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 82,448 KB
実行使用メモリ 53,904 KB
最終ジャッジ日時 2025-11-26 11:45:19
合計ジャッジ時間 2,344 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

b,n,*a = map(int,open(0).read().split())
m = (sum(a)+b)//n
ans = 1<<60
for x in a+[0,m]:
    more = less = 0
    for ai in a:
        if ai >= x: more += ai - x
        else: less += x - ai
    if more + b < less: continue
    ans = min(ans, more+less)
print(ans)
0