結果

問題 No.1858 Gorgeous Knapsack
ユーザー ysys
提出日時 2022-03-06 23:05:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 514 ms / 2,000 ms
コード長 467 bytes
コンパイル時間 363 ms
コンパイル使用メモリ 87,288 KB
実行使用メモリ 273,848 KB
最終ジャッジ日時 2023-09-28 14:47:44
合計ジャッジ時間 10,336 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,448 KB
testcase_01 AC 72 ms
71,244 KB
testcase_02 AC 72 ms
71,280 KB
testcase_03 AC 93 ms
76,236 KB
testcase_04 AC 251 ms
111,376 KB
testcase_05 AC 116 ms
84,364 KB
testcase_06 AC 259 ms
110,248 KB
testcase_07 AC 184 ms
103,656 KB
testcase_08 AC 321 ms
132,600 KB
testcase_09 AC 514 ms
192,012 KB
testcase_10 AC 221 ms
106,768 KB
testcase_11 AC 300 ms
130,036 KB
testcase_12 AC 406 ms
153,472 KB
testcase_13 AC 116 ms
82,928 KB
testcase_14 AC 80 ms
75,928 KB
testcase_15 AC 78 ms
75,744 KB
testcase_16 AC 78 ms
75,840 KB
testcase_17 AC 71 ms
71,308 KB
testcase_18 AC 72 ms
71,364 KB
testcase_19 AC 72 ms
71,308 KB
testcase_20 AC 70 ms
71,524 KB
testcase_21 AC 70 ms
71,456 KB
testcase_22 AC 72 ms
71,176 KB
testcase_23 AC 71 ms
71,444 KB
testcase_24 AC 143 ms
90,428 KB
testcase_25 AC 372 ms
153,732 KB
testcase_26 AC 316 ms
133,420 KB
testcase_27 AC 308 ms
133,380 KB
testcase_28 AC 225 ms
108,404 KB
testcase_29 AC 91 ms
76,740 KB
testcase_30 AC 95 ms
76,920 KB
testcase_31 AC 93 ms
76,752 KB
testcase_32 AC 89 ms
76,712 KB
testcase_33 AC 97 ms
76,828 KB
testcase_34 AC 497 ms
273,548 KB
testcase_35 AC 470 ms
273,848 KB
testcase_36 AC 480 ms
273,664 KB
testcase_37 AC 71 ms
71,288 KB
testcase_38 AC 87 ms
76,844 KB
testcase_39 AC 71 ms
71,280 KB
testcase_40 AC 454 ms
273,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
T = [tuple(map(int, input().split())) for i in range(N)]
dp = [[0] * (M + 1) for i in range(N + 1)]
T.sort(reverse=True)
ans = 0
TW = 0
for i in range(N):
  v, w = T[i]
  TW += w
  for j in range(min(M, TW + 1)):
    dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
    if j + w <= M:
      dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v)
      ans = max(ans, dp[i + 1][j + w] * v)

print(ans)
0