#K78707. Maximizing Non-Overlapping Tasks
Maximizing Non-Overlapping Tasks
Maximizing Non-Overlapping Tasks
You are given a list of tasks and a time window \([T_1, T_2]\). Each task is represented by its start and end times. A task is considered valid if it lies completely within the time window, i.e., its start time \(\ge T_1\) and its end time \(\le T_2\). Two tasks are considered non-overlapping if the start time of a task is not less than the end time of the previously selected task. Your goal is to determine the maximum number of non-overlapping tasks that can be selected such that each selected task is completely within the given time window.
Note: Tasks that end exactly when another begins are non-overlapping.
inputFormat
The input is given via standard input (stdin) and has the following format:
- The first line contains three space-separated integers: \(T_1\), \(T_2\) and \(n\) (the number of tasks).
- The next \(n\) lines each contain two space-separated integers representing the start and end times of a task.
It is guaranteed that \(T_1 \le T_2\) and all task times are integers.
outputFormat
Output a single integer to stdout representing the maximum number of non-overlapping tasks that can be performed within the time window \([T_1, T_2]\).
## sample1 10 3
1 3
2 5
6 9
2