Moovie Mooving
Time limit1sMemory limit256 MB
Choose the fewest movies, each used at most once, whose showings chain together to cover every moment from time 0 to time L.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Bit manipulation, Greedy
- Solved
- No attempts yet
Problem
Bessie is at the movie theater. She wants to hide from Farmer John for the whole stretch of minutes from time to time , so she has to be inside some showing at every moment of that stretch.
The theater plays movies. Movie runs for minutes and has a fixed list of showtimes. A showing of movie that starts at time lasts from to , and Bessie may walk in late and leave early, so that showing hides her at any moment between and .
Bessie never watches the same movie twice, and she cannot move to another showtime of the movie she is already watching when that showtime overlaps the one she is in. Plots confuse her when she watches too many movies, so she wants to use as few movies as she can.
Decide whether Bessie can stay inside a showing from time through time . If she can, report the smallest number of movies that lets her do it.
Input
The first line contains and .
Each of the next lines describes one movie. The line starts with the duration and the number of showtimes . The remaining integers on that line are the starting times of the showings of that movie. They are distinct, lie between and , and are given in increasing order.
, , , .
Output
Print the smallest number of movies Bessie needs to watch to stay inside a showing from time through time . Print if no choice of movies works.
Hint
In the first example Bessie sits in the first showing of the fourth movie from time to time , then in the first showing of the first movie from time to time , then in the last showing of the second movie from time to time .