#K36147. Maximum Non-Overlapping Events
Maximum Non-Overlapping Events
Maximum Non-Overlapping Events
You are given a set of events, each with a start time and an end time. Your task is to determine the maximum number of events that can be scheduled without overlapping. Two events \( (s_1, e_1) \) and \( (s_2, e_2) \) are non-overlapping if \( s_2 \geq e_1 \). Use a greedy algorithm by sorting the events based on their end times to select the maximum number of events.
Note: The input is provided via standard input (stdin) and the result should be printed to standard output (stdout).
inputFormat
The first line of input contains an integer \( n \), the number of events. The following \( n \) lines each contain two integers, representing the start time and end time of an event respectively.
Example:
3
1 2
2 3
3 4
outputFormat
Output a single integer representing the maximum number of non-overlapping events that can be scheduled.
## sample3
1 2
2 3
3 4
3