#C1878. Maximum Non-overlapping Events

    ID: 45131 Type: Default 1000ms 256MiB

Maximum Non-overlapping Events

Maximum Non-overlapping Events

You are given a list of events, each defined by a start time and an end time. The task is to determine the maximum number of events a single person can attend without any overlap.

An event is defined by the time interval \( [s_i, e_i] \), and two events \( [s_i, e_i] \) and \( [s_j, e_j] \) do not overlap if \( s_j \ge e_i \) (assuming \( s_i \le e_i \) for all events). Use a greedy strategy by sorting the events by their end times.

inputFormat

The first line of input contains a single integer \( n \) representing the number of events. The following \( n \) lines each contain two integers \( s_i \) and \( e_i \) representing the start and end times of an event.

Note: The events may not be given in any particular order.

outputFormat

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

## sample
3
1 2
2 3
3 4
3

</p>