knapsack algorithm to build system