#P2409. Y的积木

Y的积木

Description

Y has nn boxes of blocks, and each block has a weight. He wants to pick one block from each box and put them together; the total weight of this pile is the sum of the weights of the chosen blocks. Now he wants to know the weights of the kk selections with the smallest total weights. (As long as you replace any single block, it is considered a different selection. If multiple selections have the same total weight, we should output that weight multiple times.)

Input Format

The first line contains two integers, n,kn,k, as described.

In the next nn lines, line ii starts with an integer mim_i, the number of blocks in the ii-th box. On the same line, there are mim_i integers, which are the weights of the blocks.

Output Format

Output one line containing the weights of the kk selections with the smallest total weights, in nondecreasing order.

3 10
4 1 3 4 5
3 1 7 9
4 1 2 3 5

3 4 5 5 6 6 7 7 7 7

Hint

Constraints

  • For 30%30\% of the testdata, 2mi102 \le m_i \le 10, 1n101 \le n \le 10.
  • For 50%50\% of the testdata, 2mi502 \le m_i \le 50, 1n501 \le n \le 50.
  • For 100%100\% of the testdata, 2mi1002 \le m_i \le 100, 1n1001 \le n \le 100, 1k1041 \le k \le 10^4, each block’s weight is a positive integer not exceeding 100100, and the product of all mim_i is at least kk.

This problem does not stress constant factors.

Translated by ChatGPT 5