結果
問題 |
No.1858 Gorgeous Knapsack
|
ユーザー |
|
提出日時 | 2022-02-28 01:17:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 270 ms / 2,000 ms |
コード長 | 440 bytes |
コンパイル時間 | 146 ms |
コンパイル使用メモリ | 82,328 KB |
実行使用メモリ | 77,696 KB |
最終ジャッジ日時 | 2024-07-06 04:21:11 |
合計ジャッジ時間 | 5,001 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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)