結果

問題 No.1858 Gorgeous Knapsack
ユーザー roarisroaris
提出日時 2022-02-28 01:15:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 723 ms / 2,000 ms
コード長 450 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 86,852 KB
実行使用メモリ 273,976 KB
最終ジャッジ日時 2023-09-20 08:35:21
合計ジャッジ時間 11,292 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,348 KB
testcase_01 AC 80 ms
71,292 KB
testcase_02 AC 79 ms
71,048 KB
testcase_03 AC 102 ms
76,024 KB
testcase_04 AC 249 ms
111,160 KB
testcase_05 AC 122 ms
84,548 KB
testcase_06 AC 268 ms
110,552 KB
testcase_07 AC 192 ms
103,564 KB
testcase_08 AC 292 ms
132,760 KB
testcase_09 AC 523 ms
191,980 KB
testcase_10 AC 217 ms
106,804 KB
testcase_11 AC 308 ms
129,568 KB
testcase_12 AC 365 ms
166,308 KB
testcase_13 AC 130 ms
82,592 KB
testcase_14 AC 87 ms
75,952 KB
testcase_15 AC 87 ms
75,936 KB
testcase_16 AC 86 ms
75,952 KB
testcase_17 AC 80 ms
71,268 KB
testcase_18 AC 79 ms
71,396 KB
testcase_19 AC 80 ms
71,376 KB
testcase_20 AC 79 ms
71,372 KB
testcase_21 AC 79 ms
71,228 KB
testcase_22 AC 80 ms
71,184 KB
testcase_23 AC 77 ms
71,316 KB
testcase_24 AC 154 ms
90,608 KB
testcase_25 AC 382 ms
153,628 KB
testcase_26 AC 336 ms
133,204 KB
testcase_27 AC 330 ms
133,176 KB
testcase_28 AC 242 ms
108,192 KB
testcase_29 AC 106 ms
76,832 KB
testcase_30 AC 103 ms
76,752 KB
testcase_31 AC 103 ms
76,776 KB
testcase_32 AC 102 ms
76,680 KB
testcase_33 AC 112 ms
77,032 KB
testcase_34 AC 723 ms
273,904 KB
testcase_35 AC 483 ms
273,784 KB
testcase_36 AC 707 ms
273,976 KB
testcase_37 AC 79 ms
71,256 KB
testcase_38 AC 95 ms
76,628 KB
testcase_39 AC 85 ms
76,204 KB
testcase_40 AC 475 ms
273,784 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) for _ in range(N+1)]
ans = 0

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

print(ans)
0