maximum sum

There is an elevator with the lifting capability of (1 <= M <= 999).
And there is a list of N (1 <= N <= 100) numbers of positive integers ( 1<= M).
The elements to be lifted must be chosen so that the total sum is nearest to M.
The aim is for the elevator to perform minimum task.
Input
The input consists of 2 lines:
Line 1: M (lifting capability)
Line 2: number of inputs (N)
Line 3: K1, K2, K3…….Kn

Output
The output will contain 1 or more set from N list that will be lifted.
Sample Input
30
6
21 18 2 5 11 12
Sample Output
18 12
21 5
11 2
google "knapcack problem"
Topic archived. No new replies allowed.