Interesting constructive solution.
My first reaction was 0-1 Knapsack and I believe it'll work. But you don't have to use it.
Think about the min sum & max sum you can collect with exactly K boxes. Then? from min-sum, and move boxs 'right-ward' until to the target sum.