結果
| 問題 |
No.2364 Knapsack Problem
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-30 21:34:14 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 856 bytes |
| コンパイル時間 | 180 ms |
| コンパイル使用メモリ | 82,120 KB |
| 実行使用メモリ | 83,136 KB |
| 最終ジャッジ日時 | 2024-07-07 09:08:20 |
| 合計ジャッジ時間 | 22,218 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 12 TLE * 4 -- * 4 |
ソースコード
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)