結果

問題 No.1715 Dinner 2
ユーザー mahiro72mahiro72
提出日時 2021-10-23 03:06:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 786 bytes
コンパイル時間 1,030 ms
コンパイル使用メモリ 11,772 KB
実行使用メモリ 14,692 KB
最終ジャッジ日時 2023-10-24 19:54:21
合計ジャッジ時間 4,842 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,188 KB
testcase_01 AC 29 ms
10,188 KB
testcase_02 AC 31 ms
10,188 KB
testcase_03 AC 29 ms
10,188 KB
testcase_04 AC 30 ms
10,188 KB
testcase_05 AC 30 ms
10,188 KB
testcase_06 AC 29 ms
10,188 KB
testcase_07 AC 30 ms
10,188 KB
testcase_08 AC 31 ms
10,188 KB
testcase_09 AC 30 ms
10,188 KB
testcase_10 AC 30 ms
10,188 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import nlargest

N, D = map(int, input().split())
PQs = [tuple(map(int, input().split())) for _ in range(N)]

# dp[最後の料理] = 元気度
# 元気度の下界を二分探索

# new_dp[料理] = max dp[他の料理] + 差分 (下界に違反しない場合)

INF = 10 ** 9

def isok(lb):
    dp = [0] * N
    for _ in range(D):
        new_dp = [-INF] * N
        M1, M2 = nlargest(2, dp)
        if M1 == -INF:
            return False
        for i, (P, Q) in enumerate(PQs):
            M = M1 if (M1 != dp[i]) else M2
            if M - P >= lb:
                new_dp[i] = M - P + Q
        dp = new_dp
    return max(dp) > -INF


ok = -INF
ng = 1
while ng - ok > 1:
    mid = (ng + ok) // 2
    if isok(mid):
        ok  = mid
    else:
        ng = mid

print(ok)
0