結果

問題 No.198 キャンディー・ボックス2
ユーザー matsu7874matsu7874
提出日時 2015-10-20 00:47:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 511 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 8,276 KB
最終ジャッジ日時 2023-09-29 16:18:52
合計ジャッジ時間 2,515 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 15 ms
7,888 KB
testcase_10 AC 16 ms
7,848 KB
testcase_11 AC 15 ms
7,904 KB
testcase_12 AC 16 ms
8,140 KB
testcase_13 WA -
testcase_14 AC 15 ms
8,276 KB
testcase_15 AC 16 ms
8,144 KB
testcase_16 RE -
testcase_17 AC 16 ms
7,900 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 15 ms
7,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
B = int(input())
N = int(input())
C = [int(input()) for i in range(N)]
sum_c = sum(C)

if N==1:
    print(0)
    exit()

l = 0
r = (sum_c + B) // N + 1
for i in range(int(math.log(3, sum_c + B)) + 1):
    ml = (l * 2 + r) // 3
    mr = (l + r * 2) // 3
    total_l = 0
    total_r = 0
    for c in C:
        total_l += abs(ml - c)
        total_r += abs(mr - c)
    if total_r >= total_l:
        r = mr
    else:
        l = ml
# print(l, ml, total_l, mr, total_r, r)
print(min(total_l, total_r))
0