The one of the coins

Perhaps you have read that some problems are so classic that they barely need a statement. For this one, given a collection of nn coins with different values and a target amount AA, we ask you to indicate the way to add up to AA by using coins of the largest possible values. In particular, a way is better than another one if the former uses more coins of the largest value; in the event of a tie, if it uses more coins of the second largest value, etc.

Input

Input consists of several cases. Each case begins with the number of coins nn between 1 and 100, followed by nn different integer numbers v1,,vnv_1, \ldots, v_n, where 1vi100001\leq v_i\leq 10000. Finally, we have an integer number 1A1000001\leq A\leq 100000.

Output

For every case, print in non-increasing order the necessary coins to get AA, choosing the combination with coins of largest value in case of a tie. If there is no solution, print 1-1.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T12:13:50.429Z

© Jutge.org, 2006–2026.
https://jutge.org