結果

問題 No.198 キャンディー・ボックス2
ユーザー neterukunneterukun
提出日時 2021-06-15 23:44:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 636 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 87,272 KB
実行使用メモリ 71,696 KB
最終ジャッジ日時 2023-08-27 20:41:59
合計ジャッジ時間 3,564 ms
ジャッジサーバーID
(参考情報)
judge14 / 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 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 68 ms
71,544 KB
testcase_13 WA -
testcase_14 AC 67 ms
71,344 KB
testcase_15 AC 67 ms
71,024 KB
testcase_16 WA -
testcase_17 AC 68 ms
71,436 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 68 ms
71,240 KB
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 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def ternary_search_intmax(l, r, evaluate):
    while (r - l) > 1:
        mid = (r + l) // 2
        # 凸の左側に平坦が存在するときは不等号に = をつける。
        # 凸の左右に平坦が存在するときは解けない。
        if evaluate(mid) - evaluate(mid - 1) > 0:
            l = mid
        else:
            r = mid
    return l, evaluate(l)


def evaluate(mid):
    return -sum([abs(c[i] - mid) for i in range(n)])


b = int(input())
n = int(input())
c = [int(input()) for i in range(n)]


c = sorted(c, reverse=True)
cnt, ans = ternary_search_intmax(0, (sum(c) + b) // n + 1, evaluate)
print(ans)
0