공개된 정수 O와 목표 합 X가 주어질 때, X를 만드는 모든 유효한 부분집합 합에 반드시 포함되는 공개 보유자의 번호를 구한다.
어려움9동적 계획법조합론그리디아직 제출이 없습니다시간 제한2초메모리 제한512 MBJAG members began a game with integers. The game consists of N+M+1 players: N open number holders, M secret number holders, and one answerer, you.
In the preparation, an integer K is told to all N+M+1 players. N+M number holders choose their own integers per person under the following restrictions:
After the choices, N open number holders show their integers O_1,…,O_N to the answerer while secret number holders do not.
The game has Q rounds. At the beginning of each round, M secret number holders can change their numbers under the above restrictions, while open number holders cannot. Then N+M number holders select part of members among them arbitrary, calculate the sum X of the integers owned by the selected members, and tell X to the answerer. For each round, the answerer tries to identify the definitely selected open number holders from the information K, X, and O_1,…,O_N: The answerer will get points per actually selected open number holder in the answer. On the other hand, if the answer contains at least one non-selected member, you lose your points got in the round. Thus, the answerer, you, must answer only the open number holders such that the holders are definitely selected.
Your task in this problem is to write a program to determine all the open number holders whose integers are necessary to the sum for each round in order to maximize your points.
The input consists of a single test case formatted as follows.
$N$ $M$ $K$ $Q$ $O_{1}$ $\cdots$ $O_{N}$ $X_{1}$ $\cdots$ $X_{Q}$
The first line consists of four integers N, M, K, and Q. N and M are the numbers of open number holders and secret number holders respectively (1≤N,0≤M,N+M≤40). K is an integer (1≤K≤200,000). Q is the number of rounds of the game (1≤Q≤10,000).
The second line contains N integers O_1,⋯,O_N, as the i-th open number holder owns O_i (1≤O_1≤⋯≤O_N≤K).
The third line indicates Q integers X_1,⋯,X_Q (0≤X_i≤K). X_i is the sum of the integers owned by the selected members in the i-th round.
It is guaranteed that there is at least one way to compose X_i. In other words, you can assume that there is at least one integer sequence S_1,…,S_M, which represents integers owned by secret number holders, satisfying the followings:
On each sum X_i, print the indices of the open number holders whose integers are required to make up X_i. The output for each sum has to be printed in one line, in ascending order, and separated by a single space. If there is no open number holder whose integer is certainly used for X_i, print −1 in one line.