Equal sums (2)

Write a program that, given an integer number s and n integer numbers
x₁, …, x_(n), prints the subset (maybe with repeated numbers, but using
every x_(i) at most once) lexicographically largest among those whose
sum is s.

Input

Input consists of an integer number s, followed by a number n > 0,
followed by x₁, …, 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
x₁, …, x_(n) and whose sum is s. 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
