#K74532. Maximum Non-Overlapping Events

    ID: 34218 Type: Default 1000ms 256MiB

Maximum Non-Overlapping Events

Maximum Non-Overlapping Events

You are given \( n \) events. Each event is represented by a start time \( s_i \) and an end time \( e_i \). The task is to determine the maximum number of events a participant can attend without any overlaps. Two events are non-overlapping if the start time of one event is greater than or equal to the end time of the last attended event.

Input format: The first line contains an integer \( n \) indicating the number of events. This is followed by \( n \) lines, each containing two integers representing the start and end times of each event.

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

Note: It is assumed that the events are not necessarily given in sorted order.

inputFormat

The first line contains a single integer \( n \) (1 \( \leq n \leq 10^5 \)), the number of events. The next \( n \) lines each contain two integers \( s_i \) and \( e_i \) (0 \( \leq s_i < e_i \leq 10^9 \)) denoting the start and end times of each event.

outputFormat

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

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