結果

問題 No.1858 Gorgeous Knapsack
ユーザー ShirotsumeShirotsume
提出日時 2022-02-03 17:21:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 504 bytes
コンパイル時間 118 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 34,728 KB
最終ジャッジ日時 2023-09-17 22:22:15
合計ジャッジ時間 10,084 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
34,008 KB
testcase_01 AC 131 ms
29,708 KB
testcase_02 AC 128 ms
29,568 KB
testcase_03 AC 142 ms
29,600 KB
testcase_04 AC 1,285 ms
29,828 KB
testcase_05 AC 259 ms
29,644 KB
testcase_06 AC 1,380 ms
30,048 KB
testcase_07 AC 502 ms
30,160 KB
testcase_08 AC 1,937 ms
30,104 KB
testcase_09 TLE -
testcase_10 AC 868 ms
30,520 KB
testcase_11 AC 1,486 ms
30,680 KB
testcase_12 TLE -
testcase_13 AC 261 ms
30,416 KB
testcase_14 AC 136 ms
29,592 KB
testcase_15 AC 133 ms
29,524 KB
testcase_16 AC 134 ms
29,568 KB
testcase_17 AC 135 ms
29,540 KB
testcase_18 AC 136 ms
29,600 KB
testcase_19 AC 136 ms
29,608 KB
testcase_20 AC 136 ms
29,656 KB
testcase_21 AC 133 ms
29,604 KB
testcase_22 AC 132 ms
29,536 KB
testcase_23 AC 135 ms
29,684 KB
testcase_24 AC 464 ms
29,720 KB
testcase_25 AC 1,386 ms
30,548 KB
testcase_26 AC 1,625 ms
30,180 KB
testcase_27 AC 1,473 ms
29,948 KB
testcase_28 AC 648 ms
30,452 KB
testcase_29 AC 146 ms
29,992 KB
testcase_30 AC 149 ms
30,156 KB
testcase_31 AC 148 ms
30,020 KB
testcase_32 AC 144 ms
29,924 KB
testcase_33 AC 159 ms
30,460 KB
testcase_34 TLE -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
def solve(n, m, vw):
    ans = 0
    vw.sort(key = lambda x: x[0], reverse = True)
    dp = np.zeros(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 * int(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