結果

問題 No.198 キャンディー・ボックス2
ユーザー ntuda
提出日時 2024-05-27 19:21:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 504 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 56,960 KB
最終ジャッジ日時 2024-12-20 20:35:54
合計ジャッジ時間 2,629 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

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


def calc(x):
    tmp = 0
    for i in range(N):
        tmp += abs(C[i] - x)
    return tmp

lb = 0
ub = 10 ** 10 + 10
while ub - lb > 1:
    mid1 = 2 *lb / 3 + ub / 3
    mid2 = lb / 3 + 2 * ub / 3
    if calc(mid1) < calc(mid2):
        ub = mid2
    else:
        lb = mid1

ans = 10 ** 10 + 10
for j in range(int(lb),int(lb)+2):
    tmp = 0
    for i in range(N):
        tmp += abs(C[i] - j)
    ans = min(ans,tmp)
print(ans)
0