Solves a variation of knapsack problem. Target is to fulfill `capacity` using values from the `values` array while minimizing overflow over `capacity`.