Candy Boxes
Time limit1.5sMemory limit512 MB
Given N boxes, each with m candies of sweetness a at cost c, find for every k from 1 to L the minimum price of boxes so that a subset of candies sums exactly to k.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Greedy, Sorting
- Solved
- No attempts yet
Problem
A candy shop is selling special offers. Each special offer is a box containing several lion-shaped candies. There are special offers in total. The -th special offer contains candies of sweetness , and its price is .
Jongyoung's blood sugar has dropped, so he wants to buy several special offers to fix that. For every from to , find the minimum cost of buying offers so that he can eat candies whose sweetness sums to . After buying a special offer, he does not have to eat every candy in it.
Input
The first line gives and , separated by a space.
Each of the next lines gives , , , separated by spaces.
Output
For every from to , output in order the minimum cost of buying offers so that he can eat candies whose sweetness sums to , separated by spaces. If no way exists for some , output instead.