#C2374. Maximum Non-Overlapping Events
Maximum Non-Overlapping Events
Maximum Non-Overlapping Events
You are given a list of events, each represented by a pair of integers indicating the start and end times. Your task is to determine the maximum number of events you can attend, assuming that once you attend an event, you cannot attend another that overlaps with it.
One effective way to approach this problem is to sort the events by their end times and then select events greedily to ensure that you attend as many non-overlapping events as possible. Mathematically, if the events are represented as intervals \([s_i, e_i]\), you want to maximize the count of events such that if event \(i\) is chosen, then for any other event \(j\) selected, \(s_j \geq e_i\).
inputFormat
The input is given as follows:
- The first line contains a single integer n, the number of events.
- Each of the next n lines contains two integers separated by space: the start time and end time of an event.
outputFormat
Output a single integer representing the maximum number of non-overlapping events that can be attended.
## sample3
1 2
2 3
3 4
3