結果
| 問題 |
No.1858 Gorgeous Knapsack
|
| ユーザー |
brthyyjp
|
| 提出日時 | 2022-03-15 04:13:34 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 411 ms / 2,000 ms |
| コード長 | 600 bytes |
| コンパイル時間 | 208 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 76,416 KB |
| 最終ジャッジ日時 | 2024-09-21 16:57:16 |
| 合計ジャッジ時間 | 6,577 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 37 |
ソースコード
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 = [-1]*(m+1)
dp[0] = 0
ans = 0
for v, w in VW:
for i in reversed(range(m+1)):
if dp[i] == -1:
continue
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()
brthyyjp