結果

問題 No.2730 Two Types Luggage
ユーザー Ekiben542Ekiben542
提出日時 2024-04-19 21:47:30
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 963 bytes
コンパイル時間 1,145 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 246,884 KB
最終ジャッジ日時 2024-04-19 21:47:57
合計ジャッジ時間 12,734 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
51,968 KB
testcase_01 AC 43 ms
51,968 KB
testcase_02 AC 40 ms
52,224 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 68 ms
69,248 KB
testcase_11 AC 860 ms
209,180 KB
testcase_12 AC 1,054 ms
246,448 KB
testcase_13 AC 250 ms
165,788 KB
testcase_14 AC 541 ms
208,792 KB
testcase_15 AC 284 ms
101,120 KB
testcase_16 AC 306 ms
116,312 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

def knapsack(N, M, W, A, B, C):
    dp = [0] * (W + 1)
    for i in range(N):
        for w in range(W, 0, -1):
            if w - 1 >= 0:
                dp[w] = max(dp[w], dp[w - 1] + A[i])

    items = [(b, c) for b, c in zip(B, C) if b <= W]
    items.sort()

    BIT = [0] * (W + 2)
    for w in range(W + 1):
        BIT[w + 1] = max(BIT[w + 1], dp[w])
        if w < W:
            BIT[w + 2] = max(BIT[w + 2], dp[w])

    for i in range(len(items)):
        b, c = items[i]
        if i > 0 and items[i - 1][0] == b:
            continue
        for w in range(W, b - 1, -1):
            dp[w] = max(dp[w], dp[w - b] + c)
            BIT[w + 1] = max(BIT[w + 1], dp[w])
            if w < W:
                BIT[w + 2] = max(BIT[w + 2], dp[w])

    return dp[W]
N, M, W = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
print(knapsack(N, M, W, A, B, C))
0