結果
問題 | No.1858 Gorgeous Knapsack |
ユーザー |
![]() |
提出日時 | 2023-02-09 12:42:47 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 857 ms / 2,000 ms |
コード長 | 634 bytes |
コンパイル時間 | 159 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 273,536 KB |
最終ジャッジ日時 | 2024-07-06 16:17:19 |
合計ジャッジ時間 | 14,029 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 37 |
ソースコード
def f(n, m):return n * 5005 + mN, M = map(int, input().split())D = []for i in range(N):V, W = map(int, input().split())D.append( (V, W) )D.sort(reverse=True)inf = 10 ** 18dp = [-inf] * (5005 * 5005)premax = [-inf] * (M + 1)dp[0] = 0premax[0] = 0for i in range(N):Acmax = [-inf] * (M + 1)V, W = D[i]for j in range(M + 1):if j - W >= 0:dp[f(i + 1, j)] = premax[j - W] + VAcmax[j] = max(dp[f(i + 1, j)], premax[j])premax, Acmax = Acmax, premaxans = 0for i in range(N):for j in range(M + 1):ans = max(ans, dp[f(i + 1, j)] * D[i][0])print(ans)