#K81407. Maximum Non-Overlapping Events

    ID: 35746 Type: Default 1000ms 256MiB

Maximum Non-Overlapping Events

Maximum Non-Overlapping Events

You are given a list of events, each defined by its start time and end time. Your task is to select a maximum set of events such that no two events overlap. Two events \( (s_1, e_1) \) and \( (s_2, e_2) \) are non-overlapping if \( s_2 \ge e_1 \) (assuming \( e_1 \le e_2 \)). This problem is a classic example of the activity selection problem and can be efficiently solved using a greedy strategy.

Task: Determine the maximum number of non-overlapping events you can attend.

inputFormat

The first line of input contains an integer \( n \) representing the number of events. Each of the next \( n \) lines contains two integers \( s \) and \( e \) separated by space denoting the start and end time of an event.

Constraints: \( 1 \le n \le 10^5 \), and \( 0 \le s < e \le 10^9 \).

outputFormat

Output a single integer: the maximum number of non-overlapping events that can be selected.

## sample
5
1 3
2 5
3 9
6 8
8 10
3