Pergunta de entrevista da empresa Blackhawk Network

One DP problem can be solved by unbounded knapsack, just need to tweak a bit.