結果

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

ソースコード

diff #

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