結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー AEnAEn
提出日時 2023-05-26 00:29:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,986 ms / 2,000 ms
コード長 682 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 87,152 KB
実行使用メモリ 81,940 KB
最終ジャッジ日時 2023-08-26 01:07:01
合計ジャッジ時間 45,714 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,588 KB
testcase_01 AC 80 ms
76,256 KB
testcase_02 AC 90 ms
75,992 KB
testcase_03 AC 90 ms
76,292 KB
testcase_04 AC 78 ms
75,900 KB
testcase_05 AC 75 ms
71,384 KB
testcase_06 AC 90 ms
76,000 KB
testcase_07 AC 80 ms
76,056 KB
testcase_08 AC 90 ms
76,260 KB
testcase_09 AC 145 ms
77,348 KB
testcase_10 AC 126 ms
77,320 KB
testcase_11 AC 121 ms
77,500 KB
testcase_12 AC 445 ms
79,000 KB
testcase_13 AC 999 ms
80,200 KB
testcase_14 AC 301 ms
78,448 KB
testcase_15 AC 269 ms
78,084 KB
testcase_16 AC 385 ms
78,096 KB
testcase_17 AC 416 ms
78,444 KB
testcase_18 AC 76 ms
71,492 KB
testcase_19 AC 76 ms
71,272 KB
testcase_20 AC 77 ms
71,612 KB
testcase_21 AC 123 ms
77,052 KB
testcase_22 AC 108 ms
76,744 KB
testcase_23 AC 116 ms
77,092 KB
testcase_24 AC 1,626 ms
81,224 KB
testcase_25 AC 1,732 ms
81,688 KB
testcase_26 AC 1,932 ms
81,384 KB
testcase_27 AC 1,938 ms
81,656 KB
testcase_28 AC 1,372 ms
80,880 KB
testcase_29 AC 1,379 ms
80,964 KB
testcase_30 AC 76 ms
71,412 KB
testcase_31 AC 74 ms
71,288 KB
testcase_32 AC 112 ms
76,992 KB
testcase_33 AC 127 ms
77,208 KB
testcase_34 AC 138 ms
77,148 KB
testcase_35 AC 1,533 ms
81,448 KB
testcase_36 AC 1,501 ms
81,304 KB
testcase_37 AC 1,535 ms
81,332 KB
testcase_38 AC 1,263 ms
81,344 KB
testcase_39 AC 1,236 ms
81,564 KB
testcase_40 AC 1,511 ms
81,936 KB
testcase_41 AC 1,621 ms
81,524 KB
testcase_42 AC 1,286 ms
81,940 KB
testcase_43 AC 1,274 ms
81,480 KB
testcase_44 AC 1,986 ms
81,816 KB
testcase_45 AC 1,256 ms
81,796 KB
testcase_46 AC 1,298 ms
81,052 KB
testcase_47 AC 1,349 ms
81,012 KB
testcase_48 AC 1,367 ms
80,916 KB
testcase_49 AC 1,363 ms
80,804 KB
testcase_50 AC 1,383 ms
81,096 KB
testcase_51 AC 1,415 ms
80,892 KB
testcase_52 AC 1,175 ms
80,060 KB
testcase_53 AC 1,396 ms
80,916 KB
testcase_54 AC 1,249 ms
80,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N, K = map(int, input().split())
piza = [list(map(int, input().split())) for _ in range(N)]
INF = 10**9

piza.sort(key = lambda x:(-x[0]))
dp = [[-INF]*(K+1) for _ in range(2)]
dp[1][0] = 0
for i in range(N):
    P,D = piza[i]
    ndp = [[-INF]*(K+1) for _ in range(2)]
    for j in range(2):
        for k in range(K+1):
            ndp[j][k] = max(ndp[j][k],dp[j][k])
            if j:
                ndp[j][k] = max(ndp[j][k],dp[j-1][k]+D)
            if j==0 and k+P<=K:
                ndp[j][k+P] = max(ndp[j][k+P],dp[j+1][k]+D)
    dp = ndp
res = 0
for i in range(2):
    for j in range(K+1):
        res = max(res,dp[i][j])
print(res)
0