#K91782. Minimum Total Price Selection

    ID: 38052 Type: Default 1000ms 256MiB

Minimum Total Price Selection

Minimum Total Price Selection

You are given n donors. Each donor offers a list of items, each with its price. Your task is to choose exactly one item from each donor so that the total price is minimized and does not exceed the given budget b.

This problem can be formally described as follows: Given an integer n and a budget b, and for each donor a list of prices, select one price pi from the i-th donor's list such that:

\( S = \sum_{i=1}^{n} p_i \) and \( S \le b \).

If there is no valid selection where the total is within the budget, output -1. Otherwise, output the minimum total price.

inputFormat

The input is read from stdin and has the following format:

 n b
 m1 p11 p12 ... p1m1
 m2 p21 p22 ... p2m2
 ...
 mn pn1 pn2 ... pnmn

Here, the first line contains two integers, n (the number of donors) and b (the budget). Each of the following n lines starts with an integer m indicating the number of items offered by that donor, followed by m integers representing the prices.

Example:

3 300000
2 100000 200000
2 100000 150000
2 50000 80000

outputFormat

The output should be written to stdout and consists of a single integer. This integer is the minimum total price of selecting one item from each donor such that the total does not exceed the budget b. If there is no valid selection, output -1.

## sample
3 300000
2 100000 200000
2 100000 150000
2 50000 80000
250000