結果
| 問題 | No.1858 Gorgeous Knapsack |
| ユーザー |
|
| 提出日時 | 2022-02-28 01:17:37 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 187 ms / 2,000 ms |
| コード長 | 440 bytes |
| 記録 | |
| コンパイル時間 | 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 |
ソースコード
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)