#C3021. Maximum Non-Overlapping Bus Routes
Maximum Non-Overlapping Bus Routes
Maximum Non-Overlapping Bus Routes
You are given a series of bus routes. Each route is represented by its start time and end time. A route is described as an interval \( [s_i, f_i] \) where \( s_i \) is the start time and \( f_i \) is the finish time. Two routes are non-overlapping if the start time of one is greater than or equal to the finish time of the previously selected route (i.e. \( s_j \ge f_i \)).
Your task is to select as many routes as possible such that no two of the chosen routes overlap. This is a classic greedy algorithm problem where you sort the routes by their finishing times and then iteratively select the next route whose start time is not less than the end time of the last selected route.
Note: All times are positive integers. It is guaranteed that the provided routes may overlap and the goal is to maximize the number of routes that can be run sequentially on a single bus.
inputFormat
The input is read from standard input (stdin) and is formatted as follows:
- The first line contains an integer \( T \), the number of test cases.
- For each test case, the first line contains an integer \( N \), the number of bus routes.
- The second line contains \( N \) space-separated integers representing the start times of the routes.
- The third line contains \( N \) space-separated integers representing the end times of the routes.
outputFormat
For each test case, output a single integer on a new line which represents the maximum number of non-overlapping bus routes that can be selected.
## sample1
3
1 3 5
4 8 9
2
</p>