Mock CCC '19 Contest 2 S2 - Meliodas' Bar

View as PDF

Submit solution

Points: 10
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type
Boar's Hat - Meliodas' famous bar.

The "Boar's Hat" is a bar that was founded after the Seven Deadly Sins were branded as traitors of Liones. The purpose for it was to collect information about the holy knights that roamed the country. Meliodas is not a good cook; however, he has obtained a good collection of alcohol after travelling through many different regions.

A random group of people have come to the "Boar's Hat" to order some food and drinks. After the group of people finished eating and were given the bill, they forgot what they had ordered and would like to know. Can you help them find out what the people ordered given the cost of each item on the menu and the total cost?

Constraints

  • 1 \le N \le 100, 1 \le M \le 1000, N is the number of items on the menu, M is the number of orders made.
  • 1 \le c_i \le 1000, where c_i is the cost of the i^{th} item on the menu.
  • 1 \le t_i \le 3 \times 10^4, where t_i is the total cost for the i^{th} order.

Input Specification

The first line of input will contain a single integer, N, which is the number of items on the menu.

The second line of input will contain N space-separated integers, c_i, denoting the cost of the i^{th} item on the menu.

The third line of input will contain M, the number of orders that were made by the customers.

The last line of input will contain M space-separated integers, t_i, the total cost for the i^{th} order.

Output Specification

For each of the total costs given, output What?? if there may be more than one order that gives the specified sum, Impossible if the sum cannot be reached, or output, in sorted order, the items that are used to produce the sum t_i.

Sample Input 1

4
4 5 8 99
3
14 11 13

Sample Output 1

1 2 2
Impossible
What??

Comments

There are no comments at the moment.