Jewel Thief

For each knapsack capacity 1 through k, compute the maximum total value of a subset of n jewels whose sizes sum to at most the capacity.

Hard8Dynamic programmingGreedySortingNo attempts yetTime limit10sMemory limit512 MB

Problem

A large museum opened an exhibit of jewelry gathered from around the world. Edward Terrenando, a thief, is planning the biggest theft of his career there.

Edward wants the total value of the stolen jewels to be as large as possible, so he has to choose carefully which jewels to take.

Edward owns one knapsack of each size 1,2,3,,k1, 2, 3, \dots, k. A knapsack of size ss holds any set of jewels whose sizes sum to at most ss. For every knapsack size, find the maximum total value of jewels it can hold.

The same jewel cannot go into one knapsack twice, and each knapsack is a separate problem.

Input

The first line contains two integers nn and kk separated by a space (1n1,000,0001 \le n \le 1{,}000{,}000, 1k100,0001 \le k \le 100{,}000), the number of jewels and the largest knapsack size.

Each of the next nn lines describes one jewel with two integers ss and vv separated by a space (1s3001 \le s \le 300, 1v1091 \le v \le 10^9), the size and the value of that jewel.

Output

Print kk integers on one line, separated by single spaces. The ii-th integer is the maximum total value of jewels that fits in a knapsack of size ii.