結果

問題 No.1715 Dinner 2
ユーザー mahiro72mahiro72
提出日時 2021-10-23 03:07:05
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 471 ms / 2,000 ms
コード長 786 bytes
コンパイル時間 313 ms
コンパイル使用メモリ 81,892 KB
実行使用メモリ 78,328 KB
最終ジャッジ日時 2023-10-24 19:54:51
合計ジャッジ時間 8,644 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,480 KB
testcase_01 AC 41 ms
53,480 KB
testcase_02 AC 68 ms
71,412 KB
testcase_03 AC 41 ms
53,496 KB
testcase_04 AC 61 ms
69,232 KB
testcase_05 AC 49 ms
61,240 KB
testcase_06 AC 42 ms
53,496 KB
testcase_07 AC 63 ms
69,268 KB
testcase_08 AC 50 ms
61,168 KB
testcase_09 AC 42 ms
55,544 KB
testcase_10 AC 55 ms
64,564 KB
testcase_11 AC 389 ms
77,300 KB
testcase_12 AC 341 ms
77,492 KB
testcase_13 AC 298 ms
77,564 KB
testcase_14 AC 293 ms
77,164 KB
testcase_15 AC 363 ms
77,716 KB
testcase_16 AC 374 ms
77,944 KB
testcase_17 AC 303 ms
77,056 KB
testcase_18 AC 135 ms
77,060 KB
testcase_19 AC 129 ms
76,352 KB
testcase_20 AC 160 ms
77,556 KB
testcase_21 AC 81 ms
75,852 KB
testcase_22 AC 129 ms
76,644 KB
testcase_23 AC 141 ms
76,640 KB
testcase_24 AC 166 ms
77,684 KB
testcase_25 AC 158 ms
76,648 KB
testcase_26 AC 155 ms
76,688 KB
testcase_27 AC 156 ms
76,808 KB
testcase_28 AC 177 ms
77,140 KB
testcase_29 AC 174 ms
76,696 KB
testcase_30 AC 162 ms
76,832 KB
testcase_31 AC 152 ms
76,656 KB
testcase_32 AC 471 ms
77,888 KB
testcase_33 AC 464 ms
78,212 KB
testcase_34 AC 461 ms
78,328 KB
testcase_35 AC 450 ms
77,776 KB
testcase_36 AC 39 ms
53,496 KB
testcase_37 AC 41 ms
53,496 KB
testcase_38 AC 159 ms
76,780 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