and local variable

What you need is to maintain stack yourself. In stack (or stacks) you need to keep function call parameters,
Titleist Scotty Cameron Select Newport 2 Putter Sale, and local variable (you also need to reduce their count). It’s not very clear from your code whether in your knapsack statement allowed to take multiple items of same type.