#C9565. Maximum Non-Overlapping Sessions
Maximum Non-Overlapping Sessions
Maximum Non-Overlapping Sessions
You are given a collection of sessions. Each session is defined by its start and end time. Your task is to select the maximum number of sessions that do not overlap. Two sessions do not overlap if the start time of a session is greater than or equal to the end time of the previously selected session. Formally, if a session i has start time s_i
and end time e_i
, you can attend session i if s_i \ge e_{last}
, where e_{last}
is the end time of the last attended session.
Note: The sessions may not be given in sorted order. You are advised to sort the sessions by their end times to efficiently select the maximum possible non-overlapping sessions.
inputFormat
The input is read from standard input (stdin) and is structured as follows:
- An integer
n
denoting the number of sessions. n
lines follow, each containing two space-separated integers representing the start and end times of a session.
outputFormat
Output a single integer to standard output (stdout) which is the maximum number of non-overlapping sessions that can be attended.
## sample3
1 3
2 4
3 5
2
</p>