結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,836 KB
testcase_01 AC 16 ms
7,852 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 16 ms
7,840 KB
testcase_10 AC 15 ms
7,888 KB
testcase_11 AC 15 ms
7,832 KB
testcase_12 AC 15 ms
8,244 KB
testcase_13 WA -
testcase_14 AC 15 ms
8,140 KB
testcase_15 AC 15 ms
8,096 KB
testcase_16 AC 14 ms
8,040 KB
testcase_17 AC 15 ms
8,000 KB
testcase_18 AC 15 ms
7,944 KB
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
8,048 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
total_l = 0
total_r = 0

for i in range(int(math.log(sum_c + B, 3)) + 2):
    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