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 n coins with
different values and a target amount A, we ask you to indicate the way
to add up to A 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 n between 1 and 100, followed by n different integer numbers
v₁, …, v_(n), where 1 ≤ v_(i) ≤ 10000. Finally, we have an integer
number 1 ≤ A ≤ 100000.

Output

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

Problem information

Author: Unknown
Translator: Carlos Molina

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

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