#K72132. Maximum Non-overlapping Tasks
Maximum Non-overlapping Tasks
Maximum Non-overlapping Tasks
You are given a list of tasks, each represented by a start time and an end time. For each employee, your task is to determine the maximum number of tasks that can be performed without any overlaps. A task represented by the pair \( (s, f) \) can be performed after another if and only if \( s \ge f \). Use a greedy strategy to select the tasks with the earliest finish times.
Problem Statement:
Given an integer \( N \) representing the number of employees, followed by \( N \) lines of input, where each line starts with an integer \( M \) (the number of tasks for that employee) followed by \( 2M \) integers representing the start and finish times of tasks, determine and print the maximum number of non-overlapping tasks each employee can complete.
inputFormat
The first line contains an integer \( N \), the number of employees. Each of the following \( N \) lines describes one employee's tasks in the following format:
\( M\ s_1\ f_1\ s_2\ f_2\ ...\ s_M\ f_M \)
where \( M \) is the number of tasks and \( s_i \) and \( f_i \) are the start and finish times of the \( i^{th} \) task.
outputFormat
For each employee, output the maximum number of non-overlapping tasks that can be completed, each on a new line.
## sample2
3 1 3 2 5 4 6
4 1 2 2 3 3 4 4 5
2
4
</p>