Problem list
Log in
#usaco0174 · USACO 2014-2015 January Gold

Moovie Mooving

Platinum III 2.0 s 256 MB

Bessie wants to hide from Farmer John for L (1 <= L <= 100,000,000) minutes, during which she wants to watch movies continuously. She has N (1 <= N <= 20) movies to choose from, each with a certain duration and a set of showtimes during the day. Bessie may enter and exit a movie at any time during one of its showtimes, but she does not want to ever visit the same movie twice, and she cannot switch to another showtime of the same movie that overlaps the current showtime.

Determine if it is possible for her to watch movies continuously from time 0 through time L. If it is, determine the minimum number of movies she needs to see.

Input

Line 1: N and L.

The next N lines each describe a movie: its integer duration D (1 <= D <= L) and the number of showtimes C (1 <= C <= 1000), followed by C integers in the range 0..L giving the start times of the showings (distinct, in increasing order).

Output

A single integer indicating the minimum number of movies Bessie needs to see to achieve her goal. If this is impossible, output -1.

Example 1

Input
4 100
50 3 15 30 55
40 2 0 65
30 2 20 90
20 1 0
Output
3

Output details: Watch movie 4 (0-20), movie 1 (20-65), then movie 2 (65-100).

Source
USACO 2014-2015 January Gold
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code