Skip to main content
3 of 12
i need feedback or upvotes or etc

Spend maximal money

Imagine that you're going shopping. You are on a budget and just looking around the store, trying to find things you would be interested in. Eventually, you find a set amount of things. However, since you have zero morals, you want to spend the most money possible without going over or equaling your budget.

So, given a budget \$n\$ and a list of prices \$l\$, try to spend as most money as possible without the total price being greater than/equal to \$n\$.

Rules

  • Standard rules, I/O methods, and loopholes apply.
  • This is , so shortest answer wins!

Test cases

Budget    Item prices                           Output
14.50     [4.50, 2.99, 0.99, 12.99]             [12.99, 0.99]
99.99     [79.99, 100.00]                       [79.99]
2.68      [3.00]                                []
3.50      []                                    []
5.23      [5.23]                                []
26.99     [26.98, 0.01]                         [26.98]
17.00     [0.99, 1.99, 2.99, 3.99, 4.99, 5.99]  [5.99, 4.99, 3.99, 1.99]

tags:

Meta

  • Is this a duplicate?