結果

問題 No.1858 Gorgeous Knapsack
ユーザー roaris
提出日時 2022-02-28 01:17:37
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 440 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 185 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 81,792 KB
最終ジャッジ日時 2026-03-27 14:53:38
合計ジャッジ時間 4,110 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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