#K48467. Taco Tutorial Scheduling
Taco Tutorial Scheduling
Taco Tutorial Scheduling
You are given several test cases. In each test case, you are provided with a list of tutorials identified by their start and end times. Your task is to determine the maximum number of non-overlapping tutorials you can attend in each test case. Two tutorials are considered non-overlapping if the start time of one is not earlier than the end time of the other.
This problem can be optimally solved using a greedy algorithm. First, sort all tutorials by their end times. Then, select the first tutorial and continue by choosing each subsequent tutorial whose start time is greater than or equal to the end time of the last selected tutorial.
Mathematically, if the intervals are \((s_i, e_i)\) for \(i=1,2,\ldots,N\), the objective is to maximize the number of intervals selected such that \(s_{i+1} \ge e_i\) for the chosen intervals.
inputFormat
The input is given in the following format:
- The first line contains an integer \(T\) \((1 \le T \le 100)\) representing the number of test cases.
- For each test case:
- The first line contains an integer \(N\) \((1 \le N \le 10^5)\) representing the number of tutorials.
- Each of the following \(N\) lines contains two space-separated integers \(start\) and \(end\) \((1 \le start < end \le 10^9)\) representing the start and end times of a tutorial.
All input is provided via standard input (stdin).
outputFormat
For each test case, output a single integer on a new line representing the maximum number of non-overlapping tutorials that can be attended. The result should be written to standard output (stdout).
## sample2
3
1 3
2 4
3 5
4
1 2
2 3
3 4
4 5
2
4
</p>