#K72902. Maximum Non-overlapping Events
Maximum Non-overlapping Events
Maximum Non-overlapping Events
You are given a list of events, where each event is represented by a pair of integers \(s\) and \(e\) indicating its start time and end time respectively. Your task is to determine the maximum number of events that can be attended without any overlapping. Two events \((s_1, e_1)\) and \((s_2, e_2)\) are considered non-overlapping if \(s_2 \geq e_1\).
Note: The events are assumed to be in arbitrary order. The optimal solution involves sorting the events by their end times.
inputFormat
The first line of input contains an integer \(N\) representing the number of events. Each of the following \(N\) lines contains two space-separated integers representing the start and end times of an event respectively.
outputFormat
Output a single integer, the maximum number of non-overlapping events that can be attended, printed on a new line.
## sample3
1 3
2 4
3 5
2
</p>