#K86092. Project Scheduling with Limited Crews
Project Scheduling with Limited Crews
Project Scheduling with Limited Crews
You are given several construction projects, each with a start day \(a\) and an end day \(b\). Each project must be assigned a crew throughout its duration. However, there is a daily limit \(M\) on the number of crews available.
For each test case, determine whether all projects can be scheduled without exceeding the available number of crews on any day. Specifically, if at any day the number of ongoing projects exceeds \(M\), the scheduling is impossible.
The projects are provided as intervals. One efficient way to solve this problem is to use the sweep line algorithm. For every project interval \([a, b]\), you add an event of +1 at day \(a\) and an event of -1 at day \(b+1\). Sorting these events in increasing order of time allows you to accumulate the number of active projects. If at any point the cumulative sum exceeds \(M\), print "NO"; otherwise, print "YES".
inputFormat
The input is read from standard input (stdin
) and is structured as follows:
T N a1 b1 a2 b2 ... aN bN M ... (repeat for each test case)
Where:
T
is the number of test cases.- For each test case,
N
is the number of projects. - Each of the next
N
lines contains two integersa
andb
representing the start and end days of a project. M
is the maximum number of crews available per day.
outputFormat
For each test case, output a single line to standard output (stdout
) containing either "YES" if all projects can be scheduled with the available crews or "NO" otherwise.
2
3
1 5
2 6
4 8
2
4
1 2
3 4
5 6
7 8
1
NO
YES
</p>