結果

問題 No.2364 Knapsack Problem
コンテスト
ユーザー shogo314
提出日時 2023-06-30 21:34:14
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 856 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 85 ms
コンパイル使用メモリ 64,600 KB
実行使用メモリ 59,704 KB
最終ジャッジ日時 2026-10-16 17:06:39
合計ジャッジ時間 30,237 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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 s in permutations(range(N)):
    for t in permutations(range(M)):
        i, j = 0, 0
        w = 0
        v = 0
        # print(list(s), list(t))
        while True:
            # print((w, v), (i, j))
            if i < N and w+A[s[i]] <= W:
                w += A[s[i]]
                v += B[s[i]]
                ans = max(ans, v)
                i += 1
                continue
            if j < M and w - C[t[j]] >= 0:
                w -= C[t[j]]
                v -= D[t[j]]
                ans = max(ans, v)
                j += 1
                continue
            break
        # print((w, v), (i, j))
print(ans)
0