結果

問題 No.198 キャンディー・ボックス2
ユーザー roiti46
提出日時 2015-04-29 00:08:47
言語 Python2
(2.7.18)
結果
AC  
実行時間 13 ms / 1,000 ms
コード長 407 bytes
コンパイル時間 114 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2024-11-16 08:57:43
合計ジャッジ時間 1,460 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

B = int(raw_input())
N = int(raw_input())
C = [int(raw_input()) for i in xrange(N)]

ans = 10**18
l, r = -1, 10**18
while r - l > 1:
    m = (l + r) / 2
    b = sum(m - c for c in C)
    if b > B:
        r = m
    else:
        l = m
        ans = min(ans, sum(abs(m - c) for c in C))

for ci in C:
    if sum(ci - c for c in C) > B: continue
    ans = min(ans, sum(abs(ci - c) for c in C))
print ans
    
0