#jag2017summerday3j. [jag2017summer_day3_j]Sum Source Detection
[jag2017summer_day3_j]Sum Source Detection
MathJax.Hub.Config({ tex2jax: { inlineMath: [[""], ["\\(","\\)"]], processEscapes: true }}); blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 16px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }
Problem Statement
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. 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 integers 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 members among them arbitrary, 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 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.
Input
The input consists of a single test case formatted as follows.
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.
- $\\sum\_{j=1}^{N} O\_{j} + \\sum\_{k=1}^{M} S\_{k} = K$.
- There is at least one pair of subsets and such that $\\sum\_{j \\in U} O\_{j} + \\sum\_{k \\in V} S\_{k} = X\_{i}$ 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.
Sample Input 1
2 2 23 2
7 10
9 10
Output for Sample Input 1
1
-1
The first sum can be achieved only by the first open number holder's plus of a secret number holder. In this case, secret number holders have and . The second open number holder's is a candidate for the second sum . The first open holder's plus is also possible one, as secret number holders have two s.
Sample Input 2
1 1 100 3
51
49 51 100
Output for Sample Input 2
-1
1
1
The only secret number holder owns . The output for the first sum is because the open number holder's is not selected.
Sample Input 3
2 1 58152 4
575 57500
575 57577 77 0
Output for Sample Input 3
1
2
-1
-1
In this case, the only secret number holder definitely has . The output for the last sum is because no integer of open number holders is needed to form .
Sample Input 4
3 2 1500 1
99 300 1000
99
Output for Sample Input 4
1
The only way to compose is to select the first open number holder only; secret number holders have two integers between and , while the sum of them must be .
Sample Input 5
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
Output for Sample Input 5
-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
The numbers owned by the two secret number holders are and . At least one open number holder's is required to compose and respectively, but it is impossible to determine the definitely selected open number holder(s). On the other hand, needs the two open number holders who both own .