knapsack-type solution