結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー roarisroaris
提出日時 2019-12-14 23:51:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,308 ms / 2,000 ms
コード長 610 bytes
コンパイル時間 328 ms
コンパイル使用メモリ 87,148 KB
実行使用メモリ 79,836 KB
最終ジャッジ日時 2023-09-10 12:09:28
合計ジャッジ時間 32,301 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
70,940 KB
testcase_01 AC 73 ms
71,352 KB
testcase_02 AC 89 ms
76,132 KB
testcase_03 AC 83 ms
75,700 KB
testcase_04 AC 76 ms
71,200 KB
testcase_05 AC 76 ms
71,092 KB
testcase_06 AC 89 ms
76,264 KB
testcase_07 AC 76 ms
71,132 KB
testcase_08 AC 85 ms
75,820 KB
testcase_09 AC 135 ms
77,720 KB
testcase_10 AC 117 ms
76,928 KB
testcase_11 AC 119 ms
77,544 KB
testcase_12 AC 319 ms
79,836 KB
testcase_13 AC 767 ms
78,948 KB
testcase_14 AC 226 ms
78,188 KB
testcase_15 AC 224 ms
78,420 KB
testcase_16 AC 331 ms
78,480 KB
testcase_17 AC 310 ms
78,884 KB
testcase_18 AC 74 ms
71,196 KB
testcase_19 AC 74 ms
71,256 KB
testcase_20 AC 73 ms
71,196 KB
testcase_21 AC 114 ms
77,204 KB
testcase_22 AC 110 ms
77,396 KB
testcase_23 AC 111 ms
77,164 KB
testcase_24 AC 982 ms
79,008 KB
testcase_25 AC 1,084 ms
79,012 KB
testcase_26 AC 1,216 ms
78,608 KB
testcase_27 AC 1,237 ms
78,764 KB
testcase_28 AC 905 ms
78,640 KB
testcase_29 AC 894 ms
78,780 KB
testcase_30 AC 75 ms
71,228 KB
testcase_31 AC 74 ms
70,944 KB
testcase_32 AC 109 ms
77,188 KB
testcase_33 AC 118 ms
77,792 KB
testcase_34 AC 127 ms
78,484 KB
testcase_35 AC 875 ms
78,848 KB
testcase_36 AC 884 ms
78,872 KB
testcase_37 AC 865 ms
78,740 KB
testcase_38 AC 882 ms
78,784 KB
testcase_39 AC 885 ms
79,032 KB
testcase_40 AC 907 ms
78,748 KB
testcase_41 AC 1,308 ms
78,868 KB
testcase_42 AC 1,284 ms
79,076 KB
testcase_43 AC 891 ms
78,888 KB
testcase_44 AC 1,290 ms
79,036 KB
testcase_45 AC 874 ms
78,752 KB
testcase_46 AC 911 ms
78,836 KB
testcase_47 AC 894 ms
78,580 KB
testcase_48 AC 883 ms
78,564 KB
testcase_49 AC 870 ms
78,760 KB
testcase_50 AC 883 ms
78,720 KB
testcase_51 AC 883 ms
78,664 KB
testcase_52 AC 715 ms
78,684 KB
testcase_53 AC 855 ms
78,616 KB
testcase_54 AC 1,024 ms
78,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, input().split())
PD = [tuple(map(int, input().split())) for _ in range(N)]
PD.sort(key=lambda k: k[0], reverse=True)
dp = [[[-10**18]*2 for _ in range(K+1)] for _ in range(2)]
dp[0][0][0] = 0

for i in range(N):
    Pi, Di = PD[i]
    
    for j in range(K+1):
        dp[(i+1)&1][j][0] = max(dp[i&1][j][0], dp[i&1][j][1]+Di)
        
        if j-Pi>=0:
            dp[(i+1)&1][j][1] = max(dp[i&1][j][1], dp[i&1][j-Pi][0]+Di)
        else:
            dp[(i+1)&1][j][1] = dp[i&1][j][1]

ans = 0

for i in range(K+1):
    for j in range(2):
        ans = max(ans, dp[N&1][i][j])
    
print(ans)
0