#P3118. [USACO15JAN] Moovie Mooving G

    ID: 2170 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dp2015USACO单调队列O2优化状态压缩

[USACO15JAN] Moovie Mooving G

题目描述

Bessie is out at the movies. Being mischievous as always, she has decided to hide from Farmer John for LL (1L1081 \le L \le 10^8) minutes, during which time she wants to watch movies continuously. She has NN (1N201 \le N \le 20) movies to choose from, each of which has a certain duration and a set of showtimes during the day. Bessie may enter and exit a movie at any time during one if 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.

Help Bessie by determining if it is possible for her to achieve her goal of watching movies continuously from time 00 through time LL. If it is, determine the minimum number of movies she needs to see to achieve this goal (Bessie gets confused with plot lines if she watches too many movies).

输入格式

The first line of input contains NN and LL.

The next NN lines each describe a movie. They begin with its integer duration, DD (1DL1 \le D \le L) and the number of showtimes, CC (1C10001 \le C \le 1000). The remaining CC integers on the same line are each in the range 0L0 \dots L, and give the starting time of one of the showings of the movie. Showtimes are distinct, in the range 0L0 \dots L, and given in increasing order.

输出格式

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

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

3 

提示

Bessie should attend the first showing of the fourth movie from time 00 to time 2020. Then she watches the first showing of the first movie from time 2020 to time 6565. Finally she watches the last showing of the second movie from time 6565 to time 100100.