Sum Source Detection
Time limit2sMemory limit512 MB
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 players: open number holders, secret number holders, and one answerer, you.
In the preparation, an integer is told to all players. The 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 .
- Every integer owned by secret number holders is strictly less than any integer owned by open number holders.
After the choices, open number holders show their integers to the answerer while secret number holders do not.
The game has rounds. At the beginning of each round, secret number holders can change their numbers under the above restrictions, while open number holders cannot. Then number holders select part of the members among them arbitrarily, calculate the sum of the integers owned by the selected members, and tell to the answerer. For each round, the answerer tries to identify the definitely selected open number holders from the information , , and : 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 , , , and . and are the numbers of open number holders and secret number holders respectively . is an integer . is the number of rounds of the game .
The second line contains integers , as the -th open number holder owns .
The third line indicates integers . is the sum of the integers owned by the selected members in the -th round.
It is guaranteed that there is at least one way to compose . In other words, you can assume that there is at least one integer sequence , which represents integers owned by secret number holders, satisfying the followings:
- for . Note that holds.
- .
- There is at least one pair of subsets and such that holds.
Output
On each sum , print the indices of the open number holders whose integers are required to make up . 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 , print in one line.