結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー neterukunneterukun
提出日時 2020-01-01 21:41:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,809 ms / 2,000 ms
コード長 687 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 470,016 KB
最終ジャッジ日時 2024-05-02 05:55:53
合計ジャッジ時間 42,675 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
51,968 KB
testcase_01 AC 44 ms
51,840 KB
testcase_02 AC 64 ms
63,360 KB
testcase_03 AC 53 ms
59,904 KB
testcase_04 AC 45 ms
52,224 KB
testcase_05 AC 44 ms
52,096 KB
testcase_06 AC 65 ms
63,616 KB
testcase_07 AC 45 ms
52,224 KB
testcase_08 AC 62 ms
61,824 KB
testcase_09 AC 123 ms
85,248 KB
testcase_10 AC 95 ms
73,856 KB
testcase_11 AC 103 ms
81,408 KB
testcase_12 AC 376 ms
153,984 KB
testcase_13 AC 1,183 ms
351,104 KB
testcase_14 AC 256 ms
121,152 KB
testcase_15 AC 242 ms
124,032 KB
testcase_16 AC 318 ms
148,608 KB
testcase_17 AC 367 ms
166,144 KB
testcase_18 AC 46 ms
51,968 KB
testcase_19 AC 44 ms
52,096 KB
testcase_20 AC 44 ms
51,968 KB
testcase_21 AC 94 ms
73,088 KB
testcase_22 AC 83 ms
69,504 KB
testcase_23 AC 87 ms
70,656 KB
testcase_24 AC 1,441 ms
469,760 KB
testcase_25 AC 1,501 ms
469,760 KB
testcase_26 AC 1,491 ms
468,992 KB
testcase_27 AC 1,512 ms
469,632 KB
testcase_28 AC 1,151 ms
468,992 KB
testcase_29 AC 1,179 ms
468,992 KB
testcase_30 AC 43 ms
52,480 KB
testcase_31 AC 42 ms
51,840 KB
testcase_32 AC 82 ms
69,504 KB
testcase_33 AC 96 ms
73,728 KB
testcase_34 AC 111 ms
82,816 KB
testcase_35 AC 1,809 ms
469,248 KB
testcase_36 AC 1,442 ms
469,632 KB
testcase_37 AC 1,549 ms
469,248 KB
testcase_38 AC 1,617 ms
469,632 KB
testcase_39 AC 1,581 ms
469,632 KB
testcase_40 AC 1,608 ms
469,376 KB
testcase_41 AC 1,599 ms
469,376 KB
testcase_42 AC 1,194 ms
470,016 KB
testcase_43 AC 1,175 ms
469,376 KB
testcase_44 AC 1,566 ms
469,504 KB
testcase_45 AC 1,193 ms
469,632 KB
testcase_46 AC 1,230 ms
468,864 KB
testcase_47 AC 1,181 ms
469,376 KB
testcase_48 AC 1,344 ms
469,120 KB
testcase_49 AC 1,354 ms
469,248 KB
testcase_50 AC 1,194 ms
469,248 KB
testcase_51 AC 1,165 ms
469,376 KB
testcase_52 AC 1,252 ms
392,320 KB
testcase_53 AC 1,532 ms
469,248 KB
testcase_54 AC 831 ms
468,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int, input().split())
info = [list(map(int, input().split())) for i in range(n)]
info = sorted(info, reverse = True)

dp = [[[0]*(k+1) for _ in range(n+1)] for _ in range(2)]

for i in range(n):
    cost, val = info[i]
    for j in range(k+1):
        # i番目をもらわない
        dp[0][i+1][j] = dp[0][i][j]
        dp[1][i+1][j] = dp[1][i][j]
        # i番目を無料としてもらう
        if dp[1][i][j] != 0:
            dp[0][i+1][j] = max(dp[1][i][j] + val, dp[0][i+1][j])
        # i番目をお金を払ってもらう
        if j - cost >= 0:
            dp[1][i+1][j] = max(dp[0][i][j - cost] + val, dp[1][i+1][j])

print(max(dp[0][n][k], dp[1][n][k]))
0