結果

問題 No.1858 Gorgeous Knapsack
ユーザー rlangevinrlangevin
提出日時 2023-02-09 12:42:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 970 ms / 2,000 ms
コード長 634 bytes
コンパイル時間 255 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 274,320 KB
最終ジャッジ日時 2023-09-20 21:30:53
合計ジャッジ時間 15,101 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 150 ms
267,248 KB
testcase_01 AC 151 ms
267,420 KB
testcase_02 AC 154 ms
267,548 KB
testcase_03 AC 180 ms
272,532 KB
testcase_04 AC 370 ms
273,660 KB
testcase_05 AC 209 ms
272,896 KB
testcase_06 AC 424 ms
273,628 KB
testcase_07 AC 345 ms
273,256 KB
testcase_08 AC 517 ms
273,528 KB
testcase_09 AC 767 ms
273,852 KB
testcase_10 AC 333 ms
273,368 KB
testcase_11 AC 476 ms
273,560 KB
testcase_12 AC 639 ms
273,496 KB
testcase_13 AC 208 ms
273,360 KB
testcase_14 AC 147 ms
272,268 KB
testcase_15 AC 143 ms
272,084 KB
testcase_16 AC 143 ms
272,360 KB
testcase_17 AC 134 ms
271,116 KB
testcase_18 AC 135 ms
271,152 KB
testcase_19 AC 131 ms
267,504 KB
testcase_20 AC 132 ms
267,408 KB
testcase_21 AC 132 ms
267,492 KB
testcase_22 AC 134 ms
267,660 KB
testcase_23 AC 132 ms
267,624 KB
testcase_24 AC 261 ms
272,816 KB
testcase_25 AC 678 ms
273,664 KB
testcase_26 AC 569 ms
273,928 KB
testcase_27 AC 539 ms
273,472 KB
testcase_28 AC 458 ms
273,288 KB
testcase_29 AC 176 ms
273,348 KB
testcase_30 AC 175 ms
273,356 KB
testcase_31 AC 176 ms
273,284 KB
testcase_32 AC 175 ms
273,348 KB
testcase_33 AC 182 ms
273,592 KB
testcase_34 AC 970 ms
274,320 KB
testcase_35 AC 466 ms
274,192 KB
testcase_36 AC 440 ms
274,172 KB
testcase_37 AC 130 ms
267,600 KB
testcase_38 AC 169 ms
273,292 KB
testcase_39 AC 136 ms
272,068 KB
testcase_40 AC 466 ms
274,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def f(n, m):
    return n * 5005 + m

N, 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 ** 18
dp = [-inf] * (5005 * 5005)
premax = [-inf] * (M + 1)
dp[0] = 0
premax[0] = 0
for 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] + V
        Acmax[j] = max(dp[f(i + 1, j)], premax[j])
    premax, Acmax = Acmax, premax

ans = 0
for i in range(N):
    for j in range(M + 1):
        ans = max(ans, dp[f(i + 1, j)] * D[i][0])
print(ans)
0