結果

問題 No.1858 Gorgeous Knapsack
ユーザー brthyyjpbrthyyjp
提出日時 2022-03-15 04:12:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 355 ms / 2,000 ms
コード長 532 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 82,380 KB
実行使用メモリ 76,616 KB
最終ジャッジ日時 2024-09-21 16:56:30
合計ジャッジ時間 5,302 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def main():

    n, m = map(int, input().split())
    VW = []
    for i in range(n):
        v, w = map(int, input().split())
        VW.append((v, w))
    VW.sort(key=lambda x: -x[0])
    dp = [0]*(m+1)
    ans = 0
    for v, w in VW:
        for i in reversed(range(m+1)):
            if i+w <= m:
                ans = max(ans, (dp[i]+v)*v)
                dp[i+w] = max(dp[i+w], dp[i]+v)
    print(ans)

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