#K58802. Maximum Non-Overlapping Time Slots
Maximum Non-Overlapping Time Slots
Maximum Non-Overlapping Time Slots
You are given a set of time slots representing the preferred working intervals of employees. Each time slot is a pair of integers \( (s, e) \) where \( s \) is the start time and \( e \) is the end time. Your task is to select as many non-overlapping time slots as possible using a greedy strategy.
The classic greedy algorithm sorts the intervals by their end times, then iteratively picks each interval whose start time is not less than the end time of the last selected interval. This condition can be written in \( \LaTeX \) as:
$$ s_i \ge e_j $$
where \( s_i \) is the start time of the current interval and \( e_j \) is the end time of the last selected interval.
Note: Although an additional parameter \( M \) (the number of employees) is provided, it does not affect the computation in this particular problem.
inputFormat
The input is given via standard input (stdin) and is formatted as follows:
- The first line contains two integers \( M \) and \( N \) separated by a space, where \( M \) is the number of employees (unused in computation) and \( N \) is the number of time slots.
- The next \( N \) lines each contain two integers representing the start and end times of a time slot.
For example:
5 5 1 4 3 5 0 6 5 7 8 9
outputFormat
The output is a single integer printed to standard output (stdout), representing the maximum number of non-overlapping time slots that can be selected.
For the sample input above, the output should be:
3## sample
5 5
1 4
3 5
0 6
5 7
8 9
3