Knapsack problem (written in C++)