solved the knapsack problem