#K57557. Maximum Non-Overlapping Requests

    ID: 30446 Type: Default 1000ms 256MiB

Maximum Non-Overlapping Requests

Maximum Non-Overlapping Requests

You are given a set of requests, where each request is represented by a pair of integers si and ei, denoting its start and end times respectively. Two requests are considered non-overlapping if the start time of one is not less than the end time of the previously selected request, i.e. \(s_i \geq last\_end\).

Your task is to determine the maximum number of non-overlapping requests that can be selected. A common greedy strategy to solve this problem is to sort all the requests by their end times and then iteratively choose the requests that start after the last chosen request's end time.

Note: The input size can be large, so consider using an efficient sorting algorithm.

inputFormat

The first line contains an integer ( n ) ((0 \leq n \leq 10^5)), the number of requests. Each of the following ( n ) lines contains two space-separated integers ( s_i ) and ( e_i ), which represent the start and end times of a request.

outputFormat

Output a single integer representing the maximum number of non-overlapping requests.## sample

5
0 3
2 5
4 7
6 9
8 10
3