Equal sums (2)

Write a program that, given an integer number ss and nn integer numbers x1,,xnx_1, \dots, x_n, prints the subset (maybe with repeated numbers, but using every xix_i at most once) lexicographically largest among those whose sum is ss.

Input

Input consists of an integer number ss, followed by a number n>0n > 0, followed by x1,,xnx_1, \dots, x_n.

Output

Print, with the elements sorted non-increasingly, the subset that is greatest in lexicographical order among those that can be made up with x1,,xnx_1, \dots, x_n and whose sum is ss. If there is none, print “no solution”.

Hint

Sort the given numbers.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T11:58:26.197Z

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