結果

問題 No.1858 Gorgeous Knapsack
ユーザー lloyzlloyz
提出日時 2022-03-01 21:32:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 759 ms / 2,000 ms
コード長 553 bytes
コンパイル時間 447 ms
コンパイル使用メモリ 87,156 KB
実行使用メモリ 274,900 KB
最終ジャッジ日時 2023-09-22 12:12:18
合計ジャッジ時間 13,388 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,324 KB
testcase_01 AC 72 ms
71,224 KB
testcase_02 AC 73 ms
71,288 KB
testcase_03 AC 81 ms
76,344 KB
testcase_04 AC 337 ms
115,784 KB
testcase_05 AC 138 ms
84,812 KB
testcase_06 AC 367 ms
124,152 KB
testcase_07 AC 235 ms
103,948 KB
testcase_08 AC 486 ms
144,540 KB
testcase_09 AC 758 ms
192,660 KB
testcase_10 AC 301 ms
107,236 KB
testcase_11 AC 424 ms
130,576 KB
testcase_12 AC 606 ms
166,856 KB
testcase_13 AC 160 ms
83,284 KB
testcase_14 AC 82 ms
76,084 KB
testcase_15 AC 81 ms
76,252 KB
testcase_16 AC 83 ms
76,240 KB
testcase_17 AC 73 ms
71,308 KB
testcase_18 AC 73 ms
71,280 KB
testcase_19 AC 72 ms
71,220 KB
testcase_20 AC 73 ms
71,104 KB
testcase_21 AC 72 ms
71,324 KB
testcase_22 AC 73 ms
71,196 KB
testcase_23 AC 75 ms
71,280 KB
testcase_24 AC 165 ms
88,304 KB
testcase_25 AC 487 ms
160,724 KB
testcase_26 AC 444 ms
143,896 KB
testcase_27 AC 439 ms
141,336 KB
testcase_28 AC 302 ms
121,472 KB
testcase_29 AC 124 ms
78,316 KB
testcase_30 AC 123 ms
78,308 KB
testcase_31 AC 128 ms
78,352 KB
testcase_32 AC 119 ms
78,076 KB
testcase_33 AC 128 ms
78,396 KB
testcase_34 AC 759 ms
274,696 KB
testcase_35 AC 466 ms
274,460 KB
testcase_36 AC 759 ms
274,900 KB
testcase_37 AC 72 ms
71,300 KB
testcase_38 AC 113 ms
78,092 KB
testcase_39 AC 74 ms
75,960 KB
testcase_40 AC 469 ms
274,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
VW = [list(map(int, input().split())) for _ in range(n)]

VW.sort(key=lambda x: -x[0])
DP = [[-1 for _ in range(m + 1)] for _ in range(n + 1)]
DP[0][0] = 0
for i in range(n):
    v, w = VW[i]
    for j in range(m + 1):
        if DP[i][j] != -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 + w], DP[i][j] + v)
ans = 0
for i in range(1, n + 1):
    maxv = max(DP[i])
    ans = max(ans, maxv * VW[i - 1][0])
print(ans)
0