結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー brthyyjpbrthyyjp
提出日時 2021-04-21 15:03:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,042 ms / 2,000 ms
コード長 994 bytes
コンパイル時間 407 ms
コンパイル使用メモリ 86,736 KB
実行使用メモリ 85,196 KB
最終ジャッジ日時 2023-09-17 09:32:24
合計ジャッジ時間 24,566 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,184 KB
testcase_01 AC 75 ms
70,960 KB
testcase_02 AC 89 ms
75,748 KB
testcase_03 AC 80 ms
75,228 KB
testcase_04 AC 74 ms
71,176 KB
testcase_05 AC 73 ms
71,032 KB
testcase_06 AC 87 ms
75,240 KB
testcase_07 AC 74 ms
71,192 KB
testcase_08 AC 83 ms
75,280 KB
testcase_09 AC 109 ms
76,392 KB
testcase_10 AC 97 ms
75,468 KB
testcase_11 AC 99 ms
76,244 KB
testcase_12 AC 266 ms
77,616 KB
testcase_13 AC 635 ms
80,124 KB
testcase_14 AC 190 ms
76,980 KB
testcase_15 AC 155 ms
76,592 KB
testcase_16 AC 195 ms
77,212 KB
testcase_17 AC 226 ms
77,444 KB
testcase_18 AC 75 ms
71,168 KB
testcase_19 AC 74 ms
70,844 KB
testcase_20 AC 73 ms
71,192 KB
testcase_21 AC 99 ms
75,468 KB
testcase_22 AC 95 ms
75,508 KB
testcase_23 AC 104 ms
75,636 KB
testcase_24 AC 877 ms
83,476 KB
testcase_25 AC 878 ms
81,696 KB
testcase_26 AC 842 ms
79,600 KB
testcase_27 AC 827 ms
80,068 KB
testcase_28 AC 585 ms
80,124 KB
testcase_29 AC 586 ms
81,024 KB
testcase_30 AC 72 ms
71,260 KB
testcase_31 AC 73 ms
70,960 KB
testcase_32 AC 95 ms
75,352 KB
testcase_33 AC 97 ms
75,460 KB
testcase_34 AC 101 ms
75,720 KB
testcase_35 AC 750 ms
81,288 KB
testcase_36 AC 761 ms
81,748 KB
testcase_37 AC 795 ms
85,196 KB
testcase_38 AC 1,042 ms
82,776 KB
testcase_39 AC 914 ms
82,560 KB
testcase_40 AC 788 ms
79,780 KB
testcase_41 AC 728 ms
79,676 KB
testcase_42 AC 779 ms
79,616 KB
testcase_43 AC 712 ms
80,036 KB
testcase_44 AC 929 ms
79,972 KB
testcase_45 AC 1,010 ms
79,788 KB
testcase_46 AC 580 ms
80,076 KB
testcase_47 AC 583 ms
80,632 KB
testcase_48 AC 577 ms
80,804 KB
testcase_49 AC 569 ms
80,572 KB
testcase_50 AC 606 ms
80,140 KB
testcase_51 AC 574 ms
80,032 KB
testcase_52 AC 451 ms
78,956 KB
testcase_53 AC 510 ms
79,804 KB
testcase_54 AC 351 ms
79,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

def main():
    n, k = map(int, input().split())
    PD = []
    for i in range(n):
        p, d = map(int, input().split())
        PD.append((p,d))

    PD.sort(key=lambda x: -x[0])
    INF = 10**18
    dp0 = [-INF]*(k+1)
    dp1 = [-INF]*(k+1)
    dp0[0] = 0
    for p, d in PD:
        nx0 = [-INF]*(k+1)
        nx1 = [-INF]*(k+1)
        for i in range(k+1):
            nx0[i] = dp0[i]
        for i in range(k+1):
            nx1[i] = dp1[i]
        for i in range(k+1):
            if dp0[i] == -INF:
                continue
            if i+p <= k:
                nx1[i+p] = max(nx1[i+p], dp0[i]+d)
        for i in range(k+1):
            if dp1[i] == -INF:
                continue
            nx0[i] = max(nx0[i], dp1[i]+d)
        dp0 = nx0
        dp1 = nx1
    ans = -INF
    for i in range(k+1):
        ans = max(ans, dp0[i], dp1[i])
    print(ans)

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