This page is still under construction.

Parts of this page are still being built. What you see may change.

Sum Source Detection

Time limit2sMemory limit512 MB

Summary
For each queried sum X, find every open holder that appears in all valid subsets making X, where secret values must each be below the smallest open value.
Level

Medium7 of 10

Topics
Dynamic programming, Hash map, Implementation, Math
Solved
No attempts yet

Problem

JAG members began a game with integers. The game consists of N+M+1N + M + 1 players: NN open number holders, MM secret number holders, and one answerer, you.

In the preparation, an integer KK is told to all N+M+1N+M+1 players. The N+MN + M number holders choose their own integers per person under the following restrictions:

  • Each holder owns a positive integer.
  • The sum of all the integers equals KK.
  • Every integer owned by secret number holders is strictly less than any integer owned by open number holders.

After the choices, NN open number holders show their integers O1,…,ONO_{1}, \dots, O_{N} to the answerer while secret number holders do not.

The game has QQ rounds. At the beginning of each round, MM secret number holders can change their numbers under the above restrictions, while open number holders cannot. Then N+MN + M number holders select part of the members among them arbitrarily, calculate the sum XX of the integers owned by the selected members, and tell XX to the answerer. For each round, the answerer tries to identify the definitely selected open number holders from the information KK, XX, and O1,…,ONO_{1}, \dots, O_{N}: The answerer gets 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 the points you 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.

Input

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 NN, MM, KK, and QQ. NN and MM are the numbers of open number holders and secret number holders respectively (1≤N,0≤M,N+M≤40)(1 \le N, 0 \le M, N + M \le 40). KK is an integer (1≤K≤200,000)(1 \le K \le 200{,}000). QQ is the number of rounds of the game (1≤Q≤10,000)(1 \le Q \le 10{,}000).

The second line contains NN integers O1,⋯ ,ONO_{1}, \cdots, O_{N}, as the ii-th open number holder owns OiO_{i} (1≤O1≤⋯≤ON≤K)(1 \le O_{1} \le \dots \le O_{N} \le K).

The third line indicates QQ integers X1,⋯ ,XQX_{1}, \cdots, X_{Q} (0≤Xi≤K)(0 \le X_{i} \le K). XiX_{i} is the sum of the integers owned by the selected members in the ii-th round.

It is guaranteed that there is at least one way to compose XiX_{i}. In other words, you can assume that there is at least one integer sequence S1,…,SMS_{1}, \dots, S_{M}, which represents integers owned by secret number holders, satisfying the followings:

  • 0<Sj<O10 < S_{j} < O_{1} for 1≤j≤M1 \le j \le M. Note that O1=min⁡1≤k≤NOkO_{1} = \min_{1 \le k \le N} O_{k} holds.
  • ∑j=1NOj+∑k=1MSk=K\sum_{j=1}^{N} O_{j} + \sum_{k=1}^{M} S_{k} = K.
  • There is at least one pair of subsets U⊆{1,…,N}U \subseteq \{1, \dots, N\} and V⊆{1,…,M}V \subseteq \{1, \dots, M\} such that ∑j∈UOj+∑k∈VSk=Xi\sum_{j \in U} O_{j} + \sum_{k \in V} S_{k} = X_{i} holds.

Output

On each sum XiX_{i}, print the indices of the open number holders whose integers are required to make up XiX_{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 XiX_{i}, print −1-1 in one line.

Examples5

  1. Example 1

    Input
    2 2 23 2
    7 10
    9 10
    
    Expected output
    1
    -1
    
  2. Example 2

    Input
    1 1 100 3
    51
    49 51 100
    
    Expected output
    -1
    1
    1
    
  3. Example 3

    Input
    2 1 58152 4
    575 57500
    575 57577 77 0
    
    Expected output
    1
    2
    -1
    -1
    
  4. Example 4

    Input
    3 2 1500 1
    99 300 1000
    99
    
    Expected output
    1
    
  5. Example 5

    Input
    3 2 20 19
    3 3 11
    1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19 20
    
    Expected output
    -1
    -1
    -1
    -1
    -1
    -1
    1 2
    1 2
    1 2
    3
    3
    3
    3
    3
    3
    3
    1 2 3
    1 2 3
    1 2 3