結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
8,040 KB
testcase_01 AC 35 ms
7,940 KB
testcase_02 AC 28 ms
8,028 KB
testcase_03 AC 25 ms
7,916 KB
testcase_04 AC 27 ms
7,920 KB
testcase_05 AC 31 ms
7,932 KB
testcase_06 AC 27 ms
8,028 KB
testcase_07 AC 23 ms
7,900 KB
testcase_08 AC 30 ms
7,848 KB
testcase_09 AC 13 ms
7,980 KB
testcase_10 AC 13 ms
7,916 KB
testcase_11 AC 14 ms
8,040 KB
testcase_12 AC 13 ms
8,368 KB
testcase_13 AC 29 ms
7,988 KB
testcase_14 AC 14 ms
8,216 KB
testcase_15 AC 13 ms
8,372 KB
testcase_16 AC 14 ms
7,924 KB
testcase_17 AC 14 ms
7,940 KB
testcase_18 AC 13 ms
7,948 KB
testcase_19 WA -
testcase_20 AC 25 ms
8,004 KB
testcase_21 WA -
testcase_22 AC 26 ms
7,900 KB
testcase_23 WA -
testcase_24 AC 31 ms
8,020 KB
testcase_25 WA -
testcase_26 AC 29 ms
7,916 KB
testcase_27 AC 29 ms
7,948 KB
testcase_28 WA -
testcase_29 AC 34 ms
7,848 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)
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