Equal sums (2) P82660


Statement
 

pdf   zip

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.

Public test cases
  • Input

    6
    7
    1 6 0 1 3 2 0
    

    Output

    {6,0,0}
    
  • Input

    -5
    3
    6 -10 4
    

    Output

    no solution
    
  • Input

    -5
    9
    3 1 -1 -1 0 -3 0 -2 2
    

    Output

    {2,0,0,-1,-1,-2,-3}
    
  • Input

    -9
    3
    -5 6 -4
    

    Output

    {-4,-5}
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++