結果

問題 No.1858 Gorgeous Knapsack
ユーザー ys
提出日時 2022-03-06 23:10:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 407 bytes
コンパイル時間 201 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 70,016 KB
最終ジャッジ日時 2024-07-21 09:37:14
合計ジャッジ時間 4,392 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
T = [tuple(map(int, input().split())) for i in range(N)]
dp = [-1] * (M + 1)
dp[0] = 0
T.sort(reverse=True)
ans = 0
TW = 0
for i in range(N):
  v, w = T[i]
  TW += w
  for j in range(min(M, TW + 1), -1, -1):
    if dp[j] != -1 and j + w <= M:
      dp[j + w] = max(dp[j + w], dp[j] + v)
      ans = max(ans, dp[j + w] * v)

print(ans)
0