As pointed out, this looks like a variation of the knapsack
problem (although I've no idea what the purpose of the
single line is). The knapsack problem is a well studied
problem, and it is a really hard problem.
What is the background of your particular instance of this
problem?