結果
| 問題 | No.1858 Gorgeous Knapsack |
| ユーザー |
brthyyjp
|
| 提出日時 | 2022-03-15 04:12:10 |
| 言語 | PyPy3 (7.3.23 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 215 ms / 2,000 ms |
| + 469µs | |
| コード長 | 532 bytes |
| 記録 | |
| コンパイル時間 | 232 ms |
| コンパイル使用メモリ | 95,824 KB |
| 実行使用メモリ | 84,560 KB |
| 最終ジャッジ日時 | 2026-09-01 18:48:34 |
| 合計ジャッジ時間 | 5,921 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 = [0]*(m+1)
ans = 0
for v, w in VW:
for i in reversed(range(m+1)):
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