結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー NoneNone
提出日時 2021-04-29 00:37:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 916 ms / 2,000 ms
コード長 649 bytes
コンパイル時間 2,633 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 80,628 KB
最終ジャッジ日時 2023-09-22 07:26:09
合計ジャッジ時間 24,630 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,324 KB
testcase_01 AC 75 ms
71,216 KB
testcase_02 AC 89 ms
76,096 KB
testcase_03 AC 82 ms
75,972 KB
testcase_04 AC 71 ms
71,544 KB
testcase_05 AC 69 ms
71,196 KB
testcase_06 AC 83 ms
75,916 KB
testcase_07 AC 67 ms
71,220 KB
testcase_08 AC 76 ms
76,000 KB
testcase_09 AC 121 ms
77,668 KB
testcase_10 AC 109 ms
76,964 KB
testcase_11 AC 109 ms
77,652 KB
testcase_12 AC 263 ms
78,484 KB
testcase_13 AC 630 ms
79,548 KB
testcase_14 AC 208 ms
77,724 KB
testcase_15 AC 164 ms
77,464 KB
testcase_16 AC 201 ms
78,348 KB
testcase_17 AC 222 ms
78,152 KB
testcase_18 AC 72 ms
71,088 KB
testcase_19 AC 73 ms
71,216 KB
testcase_20 AC 71 ms
71,176 KB
testcase_21 AC 117 ms
77,020 KB
testcase_22 AC 108 ms
76,912 KB
testcase_23 AC 111 ms
76,744 KB
testcase_24 AC 661 ms
80,060 KB
testcase_25 AC 713 ms
80,392 KB
testcase_26 AC 718 ms
80,508 KB
testcase_27 AC 743 ms
79,780 KB
testcase_28 AC 530 ms
80,056 KB
testcase_29 AC 524 ms
79,716 KB
testcase_30 AC 71 ms
71,240 KB
testcase_31 AC 70 ms
71,388 KB
testcase_32 AC 104 ms
77,184 KB
testcase_33 AC 111 ms
76,868 KB
testcase_34 AC 113 ms
76,956 KB
testcase_35 AC 828 ms
80,460 KB
testcase_36 AC 759 ms
79,816 KB
testcase_37 AC 854 ms
80,032 KB
testcase_38 AC 733 ms
80,628 KB
testcase_39 AC 916 ms
80,148 KB
testcase_40 AC 780 ms
80,328 KB
testcase_41 AC 817 ms
79,840 KB
testcase_42 AC 786 ms
79,872 KB
testcase_43 AC 717 ms
80,420 KB
testcase_44 AC 717 ms
80,084 KB
testcase_45 AC 728 ms
79,768 KB
testcase_46 AC 514 ms
80,116 KB
testcase_47 AC 518 ms
79,564 KB
testcase_48 AC 516 ms
79,896 KB
testcase_49 AC 570 ms
80,236 KB
testcase_50 AC 542 ms
79,904 KB
testcase_51 AC 554 ms
79,784 KB
testcase_52 AC 443 ms
78,908 KB
testcase_53 AC 473 ms
79,768 KB
testcase_54 AC 263 ms
79,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,W=map(int, input().split())

data=[]
for _ in range(N):
    weight,cost=map(int, input().split())
    data.append((weight,cost))

data.sort(key=lambda x:x[0],reverse=True)


dp=[0]*(W+1)
dp2=[0]*(W+1)

for weight, cost in data:
    ndp=dp[:]
    ndp2=dp2[:]
    for w in range(W+1)[::-1]:
        if dp2[w]!=0:
            ndp[w]=max(dp2[w]+cost,ndp[w])
        if w==weight:

            ndp2[w]=max(ndp2[w],cost)
            ndp[w]=max(ndp[w],cost)

        if w>weight and dp[w-weight]!=0:
            ndp2[w]=max(ndp2[w],dp[w-weight]+cost)
            ndp[w]=max(ndp[w],dp[w-weight]+cost)
    dp=ndp
    dp2=ndp2

print(max(max(dp),max(dp2)))
0