結果

問題 No.1858 Gorgeous Knapsack
ユーザー brthyyjpbrthyyjp
提出日時 2022-03-15 04:12:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 382 ms / 2,000 ms
コード長 532 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 81,652 KB
実行使用メモリ 75,972 KB
最終ジャッジ日時 2023-10-21 15:42:20
合計ジャッジ時間 5,770 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 39 ms
53,460 KB
testcase_02 AC 38 ms
53,460 KB
testcase_03 AC 48 ms
61,536 KB
testcase_04 AC 144 ms
75,776 KB
testcase_05 AC 67 ms
75,276 KB
testcase_06 AC 151 ms
75,796 KB
testcase_07 AC 89 ms
75,820 KB
testcase_08 AC 189 ms
75,848 KB
testcase_09 AC 280 ms
75,936 KB
testcase_10 AC 119 ms
75,928 KB
testcase_11 AC 163 ms
75,916 KB
testcase_12 AC 232 ms
75,944 KB
testcase_13 AC 71 ms
75,920 KB
testcase_14 AC 44 ms
59,344 KB
testcase_15 AC 43 ms
59,324 KB
testcase_16 AC 44 ms
59,328 KB
testcase_17 AC 38 ms
53,460 KB
testcase_18 AC 38 ms
53,460 KB
testcase_19 AC 38 ms
53,460 KB
testcase_20 AC 38 ms
53,460 KB
testcase_21 AC 37 ms
53,460 KB
testcase_22 AC 38 ms
53,460 KB
testcase_23 AC 37 ms
53,460 KB
testcase_24 AC 78 ms
75,288 KB
testcase_25 AC 157 ms
75,912 KB
testcase_26 AC 169 ms
75,816 KB
testcase_27 AC 160 ms
75,816 KB
testcase_28 AC 101 ms
75,876 KB
testcase_29 AC 53 ms
64,436 KB
testcase_30 AC 55 ms
66,500 KB
testcase_31 AC 54 ms
64,444 KB
testcase_32 AC 54 ms
64,444 KB
testcase_33 AC 57 ms
66,484 KB
testcase_34 AC 382 ms
75,972 KB
testcase_35 AC 159 ms
75,792 KB
testcase_36 AC 382 ms
75,940 KB
testcase_37 AC 39 ms
53,460 KB
testcase_38 AC 52 ms
64,408 KB
testcase_39 AC 42 ms
59,324 KB
testcase_40 AC 161 ms
75,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

def main():

    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)

if __name__ == '__main__':
    main()
0