結果
問題 |
No.1858 Gorgeous Knapsack
|
ユーザー |
![]() |
提出日時 | 2022-05-30 18:38:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 736 ms / 2,000 ms |
コード長 | 486 bytes |
コンパイル時間 | 251 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 273,664 KB |
最終ジャッジ日時 | 2024-09-21 00:53:16 |
合計ジャッジ時間 | 9,709 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 37 |
ソースコード
n,m=map(int,input().split()) jue=[list(map(int,input().split())) for i in range(n)] jue.sort(reverse=True) dp=[[-1]*(m+1) for i in range(n+1)] dp[0][0]=0 ans=0 for i in range(n): for j in range(m): if dp[i][j] == -1: continue if j+jue[i][1] <= m: dp[i+1][j+jue[i][1]] = max(dp[i][j]+jue[i][0],dp[i+1][j+jue[i][1]]) ans = max(ans,(dp[i][j]+jue[i][0]) * jue[i][0]) dp[i+1][j] = max(dp[i][j],dp[i+1][j]) print(ans)