#K38447. Maximum Non-Overlapping Events

    ID: 26200 Type: Default 1000ms 256MiB

Maximum Non-Overlapping Events

Maximum Non-Overlapping Events

You are given a list of events, each specified by a start time and an end time. Your task is to determine the maximum number of events that can be attended without any overlap. Two events are considered non-overlapping if the start time of one is not less than the finish time of the previous event. In other words, if an event has a start time \(s\) and end time \(e\), you can attend it if \(s \geq E\), where \(E\) is the end time of the last attended event.

Input Format: The input is read from standard input (stdin). The first line contains an integer \(n\) denoting the number of events. This is followed by \(n\) lines, each containing two space-separated integers representing the start time and end time of an event.

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

inputFormat

The first line contains an integer \(n\) (the number of events). Each of the following \(n\) lines contains two integers \(s\) and \(e\) representing the start and end times of an event respectively.

Constraints:

  • \(1 \leq n \leq 10^5\)
  • \(s, e\) are integers.

outputFormat

Output a single integer on a new line: the maximum number of non-overlapping events that can be attended.

## sample
3
1 3
2 4
3 5
2

</p>