結果

問題 No.1715 Dinner 2
ユーザー zkouzkou
提出日時 2021-10-08 10:51:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 467 ms / 2,000 ms
コード長 786 bytes
コンパイル時間 427 ms
コンパイル使用メモリ 81,844 KB
実行使用メモリ 78,360 KB
最終ジャッジ日時 2023-10-24 11:32:17
合計ジャッジ時間 9,041 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,520 KB
testcase_01 AC 40 ms
53,520 KB
testcase_02 AC 66 ms
71,452 KB
testcase_03 AC 39 ms
53,520 KB
testcase_04 AC 59 ms
69,272 KB
testcase_05 AC 48 ms
61,268 KB
testcase_06 AC 39 ms
53,520 KB
testcase_07 AC 60 ms
69,308 KB
testcase_08 AC 47 ms
61,196 KB
testcase_09 AC 40 ms
55,568 KB
testcase_10 AC 53 ms
64,604 KB
testcase_11 AC 384 ms
77,336 KB
testcase_12 AC 337 ms
77,528 KB
testcase_13 AC 295 ms
77,588 KB
testcase_14 AC 282 ms
77,196 KB
testcase_15 AC 348 ms
77,744 KB
testcase_16 AC 367 ms
77,956 KB
testcase_17 AC 302 ms
77,084 KB
testcase_18 AC 132 ms
77,104 KB
testcase_19 AC 127 ms
76,384 KB
testcase_20 AC 157 ms
77,588 KB
testcase_21 AC 79 ms
75,888 KB
testcase_22 AC 125 ms
76,680 KB
testcase_23 AC 135 ms
76,676 KB
testcase_24 AC 162 ms
77,720 KB
testcase_25 AC 155 ms
76,680 KB
testcase_26 AC 151 ms
76,716 KB
testcase_27 AC 152 ms
76,844 KB
testcase_28 AC 173 ms
77,168 KB
testcase_29 AC 174 ms
76,732 KB
testcase_30 AC 156 ms
76,864 KB
testcase_31 AC 147 ms
76,688 KB
testcase_32 AC 467 ms
77,908 KB
testcase_33 AC 455 ms
78,200 KB
testcase_34 AC 461 ms
78,360 KB
testcase_35 AC 451 ms
77,812 KB
testcase_36 AC 38 ms
53,520 KB
testcase_37 AC 42 ms
53,520 KB
testcase_38 AC 159 ms
76,820 KB
権限があれば一括ダウンロードができます

ソースコード

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