結果
| 問題 | No.2364 Knapsack Problem |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-30 21:34:14 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 2,696 ms / 3,000 ms |
| コード長 | 856 bytes |
| 記録 | |
| コンパイル時間 | 510 ms |
| コンパイル使用メモリ | 85,268 KB |
| 実行使用メモリ | 81,260 KB |
| 最終ジャッジ日時 | 2026-03-28 23:33:34 |
| 合計ジャッジ時間 | 22,444 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
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)