Holiday
Problem Statement
Bob has a holiday from school. He decides to spend his free time—exactly M minutes—watching TV shows. There are N TV shows he likes, and each TV show i has:
A duration Di (the show runs for Di minutes whenever it starts).
Three start times ti1, ti2, ti3. A TV show begins at one of these start times and continues for Di minutes from that start time.
Bob can switch from one show to another at any moment, as long as the show he switches to is running at that moment. Bob wants to fill all M minutes with no gaps—i.e., he can start from any (x) minutes to minute x + M, he must be continuously watching some show that is running.
Determine whether it is possible for Bob to schedule his TV-watching in such a way that he spends the entire M minutes watching shows with no idle time in between.
Notes
A TV show i starts at one of its start times ti and runs for Di consecutive minutes.
Bob does not need to watch a particular TV show from its beginning or for its entire duration. He can jump into a show midway or leave it before it ends, as long as the show is still running.
Bob can instantly switch to another show (no transition time) if the other show is also running at that exact moment.
Bob doesn't watch a show more than once, i.e - he will not watch a show 2 times as different slots.
Function Description
You are to implement a function, often named solve()
in competitive programming, which reads the inputs and outputs a single line for each test case:
Print "YES" if Bob can spend all M minutes continuously watching TV shows (with no gaps).
Print "NO" otherwise.
Input Format for Custom Testing
For each test case:
An integer N — the number of TV shows Bob likes.
An integer M — the total free time Bob wants to fill.
Then N lines follow, each describing a TV show’s features. For instance, each line will contain: Di, ti1, ti2, ti3 where Di is the show’s duration, and each ti is one possible start time for that show.
Output Format
For each test case, print "YES" if Bob can spend his entire MM minutes watching TV shows back-to-back, or "NO" if it is not possible.
Constraints
1 ≤ N ≤ 10
1 ≤ M ≤ 300
0 ≤ Di, ti ≤ M
Sample Input
Sample Output
Answer
Last updated