Candy Boxes

Time limit1.5sMemory limit512 MB

Summary
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 NN special offers in total. The ii-th special offer contains mim_i candies of sweetness aia_i, and its price is cic_i.

Jongyoung's blood sugar has dropped, so he wants to buy several special offers to fix that. For every kk from 11 to LL, find the minimum cost of buying offers so that he can eat candies whose sweetness sums to kk. After buying a special offer, he does not have to eat every candy in it.

Input

The first line gives NN and LL, separated by a space. (1≤N,L≤10 000)(1 \le N, L \le 10\,000)

Each of the next NN lines gives aia_i, mim_i, cic_i, separated by spaces. (1≤ai,mi,ci≤10 000)(1 \le a_i, m_i, c_i \le 10\,000)

Output

For every kk from 11 to LL, output in order the minimum cost of buying offers so that he can eat candies whose sweetness sums to kk, separated by spaces. If no way exists for some kk, output −1-1 instead.

Examples2

  1. Example 1

    Input
    5 20
    1 1 5
    2 1 2
    3 1 3
    4 1 7
    5 1 6
    
    Expected output
    5 2 3 7 5 9 8 9 12 11 15 16 21 18 23 -1 -1 -1 -1 -1 
  2. Example 2

    Input
    3 10
    2 3 1
    2 1 2
    3 1 3
    
    Expected output
    -1 1 3 1 4 1 4 3 4 -1