結果

問題 No.1858 Gorgeous Knapsack
ユーザー ShirotsumeShirotsume
提出日時 2022-02-03 17:17:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 315 ms / 2,000 ms
コード長 479 bytes
コンパイル時間 351 ms
コンパイル使用メモリ 87,256 KB
実行使用メモリ 78,064 KB
最終ジャッジ日時 2023-09-17 22:20:29
合計ジャッジ時間 7,125 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,324 KB
testcase_01 AC 71 ms
71,324 KB
testcase_02 AC 71 ms
71,468 KB
testcase_03 AC 82 ms
75,604 KB
testcase_04 AC 139 ms
76,984 KB
testcase_05 AC 89 ms
76,408 KB
testcase_06 AC 150 ms
77,788 KB
testcase_07 AC 125 ms
77,808 KB
testcase_08 AC 190 ms
77,616 KB
testcase_09 AC 216 ms
78,040 KB
testcase_10 AC 147 ms
78,048 KB
testcase_11 AC 159 ms
78,064 KB
testcase_12 AC 223 ms
78,008 KB
testcase_13 AC 116 ms
77,968 KB
testcase_14 AC 77 ms
75,236 KB
testcase_15 AC 73 ms
75,616 KB
testcase_16 AC 77 ms
75,000 KB
testcase_17 AC 72 ms
71,132 KB
testcase_18 AC 71 ms
71,436 KB
testcase_19 AC 71 ms
71,320 KB
testcase_20 AC 71 ms
71,392 KB
testcase_21 AC 70 ms
71,220 KB
testcase_22 AC 72 ms
71,300 KB
testcase_23 AC 69 ms
71,204 KB
testcase_24 AC 94 ms
76,188 KB
testcase_25 AC 159 ms
78,052 KB
testcase_26 AC 158 ms
77,828 KB
testcase_27 AC 156 ms
77,664 KB
testcase_28 AC 131 ms
78,032 KB
testcase_29 AC 107 ms
77,496 KB
testcase_30 AC 107 ms
78,032 KB
testcase_31 AC 104 ms
77,700 KB
testcase_32 AC 105 ms
77,952 KB
testcase_33 AC 109 ms
77,876 KB
testcase_34 AC 313 ms
77,896 KB
testcase_35 AC 179 ms
77,992 KB
testcase_36 AC 315 ms
77,868 KB
testcase_37 AC 71 ms
71,400 KB
testcase_38 AC 105 ms
77,736 KB
testcase_39 AC 76 ms
75,504 KB
testcase_40 AC 172 ms
77,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(n, m, vw):
    ans = 0
    vw.sort(key = lambda x: x[0], reverse = True)
    dp = [0] * (m + 1)
    for i in range(n):
        v, w = vw[i]
        for j in range(m + 1, -1, -1):
            if j + w <= m:
                if dp[j + w] < dp[j] + v:
                    dp[j + w] = dp[j] + v
                    ans = max(ans, v * dp[j + w])
    return ans

n, m = map(int,input().split())

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

print(solve(n, m, vw))
0