Imagine that we have
n
numbers. Given a certain numberk
. We need to display the numbers, which together will give the closest possible number tok
from all possible combinations.For example: 4 numbers are given:
8, 6, 3, 1
. Given the numberk: k=13
. The answer will be:8, 3, 1
, because8 + 3 + 1 = 12
is the maximum number of possible combinations close to13
.
PS: there are no limitations. This is not an olympiad challenge, just for a project at school. 1<n<50
. 1<k<1000
.
If possible, please write the program in pascal, but you can also in C ++. I need to understand the algorithm.