結果

問題 No.1858 Gorgeous Knapsack
ユーザー brthyyjpbrthyyjp
提出日時 2022-03-15 04:10:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 360 ms / 2,000 ms
コード長 338 bytes
コンパイル時間 843 ms
コンパイル使用メモリ 81,648 KB
実行使用メモリ 76,244 KB
最終ジャッジ日時 2023-10-21 15:41:10
合計ジャッジ時間 7,132 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,400 KB
testcase_01 AC 40 ms
53,400 KB
testcase_02 AC 40 ms
53,400 KB
testcase_03 AC 50 ms
61,772 KB
testcase_04 AC 144 ms
76,060 KB
testcase_05 AC 77 ms
75,408 KB
testcase_06 AC 154 ms
76,076 KB
testcase_07 AC 107 ms
76,092 KB
testcase_08 AC 188 ms
76,080 KB
testcase_09 AC 264 ms
76,168 KB
testcase_10 AC 129 ms
76,132 KB
testcase_11 AC 144 ms
76,160 KB
testcase_12 AC 222 ms
76,152 KB
testcase_13 AC 91 ms
76,244 KB
testcase_14 AC 47 ms
59,568 KB
testcase_15 AC 45 ms
59,552 KB
testcase_16 AC 45 ms
59,560 KB
testcase_17 AC 41 ms
53,400 KB
testcase_18 AC 41 ms
53,400 KB
testcase_19 AC 39 ms
53,400 KB
testcase_20 AC 40 ms
53,400 KB
testcase_21 AC 39 ms
53,400 KB
testcase_22 AC 40 ms
53,400 KB
testcase_23 AC 39 ms
53,400 KB
testcase_24 AC 88 ms
75,416 KB
testcase_25 AC 198 ms
76,160 KB
testcase_26 AC 182 ms
76,092 KB
testcase_27 AC 153 ms
76,084 KB
testcase_28 AC 140 ms
76,132 KB
testcase_29 AC 73 ms
72,940 KB
testcase_30 AC 73 ms
72,932 KB
testcase_31 AC 74 ms
72,944 KB
testcase_32 AC 75 ms
72,944 KB
testcase_33 AC 80 ms
74,256 KB
testcase_34 AC 360 ms
76,180 KB
testcase_35 AC 177 ms
76,148 KB
testcase_36 AC 317 ms
76,184 KB
testcase_37 AC 38 ms
53,400 KB
testcase_38 AC 71 ms
72,916 KB
testcase_39 AC 43 ms
59,552 KB
testcase_40 AC 176 ms
76,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
VW = []
for i in range(n):
    v, w = map(int, input().split())
    VW.append((v, w))
VW.sort(key=lambda x: -x[0])
dp = [0]*(m+1)
ans = 0
for v, w in VW:
    for i in reversed(range(m+1)):
        if i+w <= m:
            ans = max(ans, (dp[i]+v)*v)
            dp[i+w] = max(dp[i+w], dp[i]+v)
print(ans)
0