title: Algorithm to find elements best fitting in a particular amount
body: <p>I'm looking for an algorithm to solve the follwoing problem (I will explain it with an example):</p>
  
  <p>Let say I have 10.000 $ available amount and following costs I can finance using my amount:</p>
  
  <p>cost 1: 1.000 $</p>
  
  <p>cost 2: 3.000 $</p>
  
  <p>cost 3: 4.000 $</p>
  
  <p>cost 4: 5.000 $</p>
  
  <p>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.</p>
  
  <p>In my example it would be: cost 1 + cost 3 + cost 4.</p>
  
  <p>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.</p>
  
  <p>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.</p>