#K16081. Maximum Non-Overlapping Events

    ID: 24499 Type: Default 1000ms 256MiB

Maximum Non-Overlapping Events

Maximum Non-Overlapping Events

You are given a list of events, where each event is represented by its start time and end time. Your task is to determine the maximum number of non-overlapping events that can be scheduled.

An event is defined as an interval (s,e)(s, e) where ss is the start time and ee is the end time. Two events (s1,e1)(s_1, e_1) and (s2,e2)(s_2, e_2) are non-overlapping if and only if s2e1s_2 \ge e_1.

You may consider using a greedy algorithm that sorts the events by their end times to achieve an optimal solution.

inputFormat

The first line contains an integer nn representing the number of events. Each of the following nn lines contains two integers separated by a space, representing 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 scheduled.## sample

5
1 5
2 6
1 3
3 4
5 7
3