結果
| 問題 |
No.2364 Knapsack Problem
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-30 21:59:11 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 992 bytes |
| コンパイル時間 | 230 ms |
| コンパイル使用メモリ | 82,080 KB |
| 実行使用メモリ | 82,640 KB |
| 最終ジャッジ日時 | 2024-07-07 09:45:17 |
| 合計ジャッジ時間 | 5,382 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 TLE * 1 -- * 14 |
ソースコード
from itertools import product, 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 pr1 in product((0, 1), repeat=N):
for pr2 in product((0, 1), repeat=M):
Wc = []
wi, vi = 0, 0
for i in range(N):
if pr1[i]:
Wc.append(A[i])
wi += A[i]
vi += B[i]
for i in range(M):
if pr2[i]:
Wc.append(-C[i])
wi -= C[i]
vi -= D[i]
if wi < 0 or W < wi:
continue
for per in permutations(Wc):
wk = 0
flag = True
for p in per:
wk += p
if wk < 0 or W < wk:
flag = False
continue
if flag:
ans = max(ans, vi)
break
print(ans)