結果
| 問題 |
No.2364 Knapsack Problem
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-30 21:32:49 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 993 bytes |
| コンパイル時間 | 265 ms |
| コンパイル使用メモリ | 82,244 KB |
| 実行使用メモリ | 77,040 KB |
| 最終ジャッジ日時 | 2024-07-07 09:06:08 |
| 合計ジャッジ時間 | 2,852 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 11 WA * 9 |
ソースコード
import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd
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 bit in range(1<<(n+m)):
v= 0
posw = []
negw = []
for i in range(n+m):
if not(bit>>i) & 1: continue
if i < n:
posw.append(a[i])
v += b[i]
else:
negw.append(c[i-n])
v -= d[i-n]
posw.sort()
negw.sort()
negw = negw[::-1]
now = 0
ok = 1
while posw:
now += posw.pop()
ok &= (0<=now<= W)
while negw and negw[-1] <= now:
now -= negw.pop()
while negw:
now -= negw.pop()
ok &= (0<=now<= W)
ans = max(ans, ok*v)
print(ans)