結果

問題 No.198 キャンディー・ボックス2
ユーザー tnoda_
提出日時 2015-08-20 16:32:24
言語 Python2
(2.7.18)
結果
AC  
実行時間 12 ms / 1,000 ms
コード長 311 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2024-11-16 09:05:10
合計ジャッジ時間 1,356 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

B = input()
N = input()
C = [input() for i in range(N)]


def sim(x):
    return sum(abs(y - x) for y in C)

lb = 0
ub = (sum(C) + B) / N
while ub - lb > 2:
    lm = (lb*2+ub)/3
    um = (lb+ub*2)/3
    if sim(lm) < sim(um):
        ub = um
    else:
        lb = lm
print(min(sim(ub), sim(lb), sim((ub+lb)/2)))
0