#K69902. Tutor All Students
Tutor All Students
Tutor All Students
You are given a number of students and a set of tutoring sessions. Each session covers a continuous range of students. The goal is to determine if it is possible to cover all the students, from student 1 to student N, using one or more of the provided sessions.
For each test case, you are provided with:
- N: The total number of students.
- M: The total number of tutoring sessions available.
- A list of M sessions, where each session is described by two integers A and B (with \(1 \leq A \leq B \leq N\)). A session covers all students numbered from A to B (inclusive).
Your task is to decide whether the union of selected sessions can form a continuous cover of the range \([1, N]\). If they can, print YES
; otherwise, print NO
for that test case.
Note: Sessions may overlap and can be used in combination. The solution should use a greedy strategy to choose sessions that extend the current coverage as far as possible.
inputFormat
The input is given from standard input (stdin) and has the following format:
T N1 M1 A11 B11 A12 B12 ... A1M1 B1M1 N2 M2 A21 B21 ... A2M2 B2M2 ...
Here, T is the number of test cases. For each test case, the first line contains two integers N and M. The next M lines contain two integers each representing the range [A, B] of a tutoring session.
outputFormat
For each test case, output a single line containing either YES
if it is possible to cover all students from 1 to N using the given sessions, or NO
if it is not.
1
5 3
1 2
2 4
3 5
YES
</p>