Solves a variation of knapsack problem.
Target is to fulfill capacity
using values from the values
array while minimizing overflow over capacity
.
The problem is NP-complete, so we try some heuristics here to get as close to ideal as fast as possible. Feel free to try and improve.