結果

問題 No.198 キャンディー・ボックス2
ユーザー matsu7874matsu7874
提出日時 2015-10-20 00:56:46
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 38 ms / 1,000 ms
コード長 544 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 8,392 KB
最終ジャッジ日時 2023-08-10 08:06:04
合計ジャッジ時間 2,709 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
8,072 KB
testcase_01 AC 38 ms
7,992 KB
testcase_02 AC 31 ms
7,984 KB
testcase_03 AC 27 ms
7,984 KB
testcase_04 AC 32 ms
7,948 KB
testcase_05 AC 36 ms
7,984 KB
testcase_06 AC 33 ms
7,908 KB
testcase_07 AC 27 ms
8,080 KB
testcase_08 AC 35 ms
7,992 KB
testcase_09 AC 17 ms
7,876 KB
testcase_10 AC 16 ms
7,824 KB
testcase_11 AC 16 ms
7,928 KB
testcase_12 AC 16 ms
8,308 KB
testcase_13 AC 35 ms
7,984 KB
testcase_14 AC 16 ms
8,392 KB
testcase_15 AC 16 ms
8,204 KB
testcase_16 AC 16 ms
7,952 KB
testcase_17 AC 16 ms
8,048 KB
testcase_18 AC 17 ms
7,872 KB
testcase_19 AC 20 ms
7,984 KB
testcase_20 AC 27 ms
7,992 KB
testcase_21 AC 29 ms
7,928 KB
testcase_22 AC 30 ms
7,868 KB
testcase_23 AC 35 ms
7,940 KB
testcase_24 AC 35 ms
7,952 KB
testcase_25 AC 33 ms
7,908 KB
testcase_26 AC 33 ms
7,964 KB
testcase_27 AC 34 ms
7,956 KB
testcase_28 AC 38 ms
8,080 KB
testcase_29 AC 38 ms
7,988 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)*200) + 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