結果

問題 No.2364 Knapsack Problem
ユーザー detteiuu
提出日時 2025-03-04 03:40:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 822 bytes
コンパイル時間 426 ms
コンパイル使用メモリ 82,636 KB
実行使用メモリ 84,768 KB
最終ジャッジ日時 2025-03-04 03:40:57
合計ジャッジ時間 7,087 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 9 WA * 1 TLE * 1 -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import permutations

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()))
D = list(map(int, input().split()))

ans = 0
for perm1 in permutations(range(N)):
    for perm2 in permutations(range(M)):
        idx1 = 0
        idx2 = 0
        w = 0
        v = 0
        while idx1 < N:
            if w+A[perm1[idx1]] <= W:
                w += A[perm1[idx1]]
                v += B[perm1[idx1]]
                ans = max(ans, v)
                idx1 += 1
            else:
                while idx2 < M and W < w+A[perm1[idx1]]:
                    w -= C[perm2[idx2]]
                    v -= D[perm2[idx2]]
                    idx2 += 1
                if W < w+A[perm1[idx1]]:
                    break

print(ans)
0