結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー ttrttr
提出日時 2020-01-30 21:19:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,806 ms / 2,000 ms
コード長 823 bytes
コンパイル時間 1,399 ms
コンパイル使用メモリ 86,764 KB
実行使用メモリ 469,888 KB
最終ジャッジ日時 2023-10-14 08:50:25
合計ジャッジ時間 42,116 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,148 KB
testcase_01 AC 73 ms
71,164 KB
testcase_02 AC 88 ms
75,612 KB
testcase_03 AC 83 ms
75,528 KB
testcase_04 AC 74 ms
71,344 KB
testcase_05 AC 73 ms
70,940 KB
testcase_06 AC 89 ms
75,948 KB
testcase_07 AC 74 ms
71,388 KB
testcase_08 AC 82 ms
75,620 KB
testcase_09 AC 127 ms
85,688 KB
testcase_10 AC 112 ms
81,644 KB
testcase_11 AC 113 ms
82,120 KB
testcase_12 AC 415 ms
150,492 KB
testcase_13 AC 1,232 ms
348,920 KB
testcase_14 AC 263 ms
112,124 KB
testcase_15 AC 210 ms
124,740 KB
testcase_16 AC 275 ms
148,092 KB
testcase_17 AC 310 ms
165,484 KB
testcase_18 AC 71 ms
71,456 KB
testcase_19 AC 73 ms
71,124 KB
testcase_20 AC 73 ms
71,168 KB
testcase_21 AC 112 ms
81,124 KB
testcase_22 AC 98 ms
75,676 KB
testcase_23 AC 103 ms
75,692 KB
testcase_24 AC 1,602 ms
467,624 KB
testcase_25 AC 1,714 ms
469,492 KB
testcase_26 AC 1,466 ms
469,684 KB
testcase_27 AC 1,455 ms
469,544 KB
testcase_28 AC 1,010 ms
469,648 KB
testcase_29 AC 930 ms
469,392 KB
testcase_30 AC 73 ms
71,176 KB
testcase_31 AC 73 ms
71,308 KB
testcase_32 AC 99 ms
75,748 KB
testcase_33 AC 103 ms
75,716 KB
testcase_34 AC 122 ms
84,012 KB
testcase_35 AC 1,760 ms
469,888 KB
testcase_36 AC 1,752 ms
469,588 KB
testcase_37 AC 1,789 ms
469,480 KB
testcase_38 AC 1,806 ms
469,652 KB
testcase_39 AC 1,789 ms
469,860 KB
testcase_40 AC 1,523 ms
469,672 KB
testcase_41 AC 1,505 ms
469,620 KB
testcase_42 AC 1,474 ms
469,560 KB
testcase_43 AC 1,475 ms
469,656 KB
testcase_44 AC 1,474 ms
469,616 KB
testcase_45 AC 1,470 ms
469,512 KB
testcase_46 AC 1,040 ms
469,380 KB
testcase_47 AC 942 ms
469,680 KB
testcase_48 AC 924 ms
469,376 KB
testcase_49 AC 933 ms
469,260 KB
testcase_50 AC 927 ms
469,384 KB
testcase_51 AC 926 ms
469,280 KB
testcase_52 AC 1,239 ms
393,124 KB
testcase_53 AC 1,461 ms
469,392 KB
testcase_54 AC 678 ms
469,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    N,K = map(int, input().split())
    L = []
    for _ in range(N):
        p,d = map(int, input().split())
        L.append((p, d))

    L.sort(reverse=True)
    dp0 = [[0]*(K+1) for _ in range(N+1)]
    dp1 = [[0]*(K+1) for _ in range(N+1)]
    for i in range(N):
        for j in range(K+1):
            if j < L[i][0] and dp1[i][j] > 0:
                dp0[i+1][j] = max(dp0[i][j], dp1[i][j]+L[i][1])
            elif j < L[i][0]:
                dp0[i+1][j] = dp0[i][j]
            else:
                if dp1[i][j] > 0:
                    dp0[i+1][j] = max(dp0[i][j], dp1[i][j]+L[i][1])
                else:
                    dp0[i+1][j] = dp0[i][j]
                dp1[i+1][j] = max(dp1[i][j], dp0[i][j-L[i][0]]+L[i][1])

    print(max(dp0[N][K], dp1[N][K]))

if __name__ == "__main__":
    main()
0