結果

問題 No.1858 Gorgeous Knapsack
ユーザー roarisroaris
提出日時 2022-02-28 01:17:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 325 ms / 2,000 ms
コード長 440 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 78,500 KB
最終ジャッジ日時 2023-09-20 08:38:16
合計ジャッジ時間 7,819 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,452 KB
testcase_01 AC 78 ms
71,380 KB
testcase_02 AC 75 ms
71,128 KB
testcase_03 AC 92 ms
76,120 KB
testcase_04 AC 168 ms
77,736 KB
testcase_05 AC 108 ms
77,304 KB
testcase_06 AC 182 ms
77,752 KB
testcase_07 AC 147 ms
77,332 KB
testcase_08 AC 189 ms
77,796 KB
testcase_09 AC 325 ms
78,036 KB
testcase_10 AC 158 ms
77,892 KB
testcase_11 AC 202 ms
77,904 KB
testcase_12 AC 224 ms
78,336 KB
testcase_13 AC 112 ms
77,860 KB
testcase_14 AC 86 ms
76,016 KB
testcase_15 AC 83 ms
76,120 KB
testcase_16 AC 85 ms
76,064 KB
testcase_17 AC 80 ms
71,348 KB
testcase_18 AC 78 ms
71,300 KB
testcase_19 AC 77 ms
71,128 KB
testcase_20 AC 78 ms
71,136 KB
testcase_21 AC 77 ms
71,412 KB
testcase_22 AC 80 ms
71,296 KB
testcase_23 AC 79 ms
71,300 KB
testcase_24 AC 126 ms
77,328 KB
testcase_25 AC 280 ms
77,888 KB
testcase_26 AC 223 ms
77,636 KB
testcase_27 AC 233 ms
77,416 KB
testcase_28 AC 177 ms
77,920 KB
testcase_29 AC 97 ms
76,964 KB
testcase_30 AC 96 ms
76,828 KB
testcase_31 AC 98 ms
76,852 KB
testcase_32 AC 98 ms
76,880 KB
testcase_33 AC 102 ms
76,580 KB
testcase_34 AC 265 ms
78,364 KB
testcase_35 AC 213 ms
78,420 KB
testcase_36 AC 264 ms
78,500 KB
testcase_37 AC 77 ms
71,560 KB
testcase_38 AC 92 ms
76,880 KB
testcase_39 AC 83 ms
76,032 KB
testcase_40 AC 216 ms
78,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
VW = [tuple(map(int, input().split())) for _ in range(N)]
VW.sort(reverse=True)
dp = [0]*(M+1)
ans = 0

for i in range(N):
    V, W = VW[i]
    ndp = [0]*(M+1)
    
    for j in range(M+1):
        ndp[j] = max(ndp[j], dp[j])
        
        if j+W<=M:
            ndp[j+W] = max(ndp[j+W], dp[j]+V)
            ans = max(ans, ndp[j+W]*V)
    
    dp = ndp

print(ans)
0