#K10781. Book Assignment Challenge
Book Assignment Challenge
Book Assignment Challenge
You are given N books and M students. Each book has a specified difficulty level. Every student has a preferred difficulty range \([L, R]\) and a requirement of reading at least K books within that range.
Your task is to determine whether it is possible to satisfy every student’s requirement. Note that the same book can be counted for multiple students if it lies in their respective acceptable range.
Input Constraints:
- The first line contains two integers \(N\) and \(M\).
- The second line contains \(N\) integers representing the difficulty levels of the books.
- Each of the next \(M\) lines contains three integers \(L, R, K\), which indicate that a student accepts books with difficulty in the range \([L, R]\) and requires at least \(K\) such books.
Examples:
For instance, if you have 5 books with difficulties [3, 8, 7, 5, 9] and 3 students with constraints as follows:
1. \(L = 1, R = 6, K = 2\)
2. \(L = 5, R = 10, K = 2\)
3. \(L = 7, R = 8, K = 1\)
The result should be YES
because each student has enough books available in their preferred range.
inputFormat
The input is given via standard input (stdin
) and is formatted as follows:
N M b1 b2 ... bN L1 R1 K1 L2 R2 K2 ... LM RM KM
Where:
N
is the number of books,M
is the number of students,b1, b2, ..., bN
are the difficulty levels of the books,- Each of the following
M
lines contains three integers \(L, R, K\) representing one student's acceptable difficulty range and the minimum number of books required.
outputFormat
The output should be printed to standard output (stdout
) as a single line containing either YES
if it is possible to assign the books according to the given constraints, or NO
otherwise.
5 3
3 8 7 5 9
1 6 2
5 10 2
7 8 1
YES
</p>