I'm looking for an algorithm to solve the follwoing problem (I will explain it with an example):
Let say I have 10.000 $ available amount and following costs I can finance using my amount:
cost 1: 1.000 $
cost 2: 3.000 $
cost 3: 4.000 $
cost 4: 5.000 $
The costs cannot be paid partially so either you pay the whole cost or you don't pay it at all. What I am looking for is an algorithm which helps me find the combination of costs which will not exceed available amount, but on the other side use the most part or the whole available amount.
In my example it would be: cost 1 + cost 3 + cost 4.
I would like also to add an parameter which determines how many costs can be maximally financed. If I say in my example that only two costs can be payed, cost 3 and cost 4 will be returned.
My approach would be to check all available combinations, sum them and pick the one which best uses the available amount. I wonder however if there is a simpliest way to find the optimal combination.