#C2179. Maximum Non-overlapping Events

    ID: 45466 Type: Default 1000ms 256MiB

Maximum Non-overlapping Events

Maximum Non-overlapping Events

You are given a list of events, each with a start time and an end time. Your task is to determine the maximum number of events a student can attend without any overlaps. An event i is represented as an interval \([s_i, e_i]\), and two events \(i\) and \(j\) are non-overlapping if \(s_j \ge e_i\) when \(e_i \le e_j\).

Hint: A greedy algorithm that sorts the events by their finishing times is an efficient approach. After sorting, select the event with the earliest end time that does not conflict with the previously selected event.

inputFormat

The first line contains an integer \(n\) representing the number of events. Each of the next \(n\) lines contains two space-separated integers representing the start and end times of an event. Input is provided via standard input (stdin).

outputFormat

Output a single integer representing the maximum number of non-overlapping events a student can attend. The output should be written to standard output (stdout).

## sample
5
1 3
2 4
3 5
6 8
7 9
3