#K56667. Maximum Non-overlapping Study Sessions

    ID: 30250 Type: Default 1000ms 256MiB

Maximum Non-overlapping Study Sessions

Maximum Non-overlapping Study Sessions

You are given n study sessions, each represented by a start time and an end time. Your task is to determine the maximum number of sessions that can be attended without any overlap.

Two sessions, \((a, b)\) and \((c, d)\), are considered non-overlapping if \(a \ge d\) or \(c \ge b\). A common strategy is to sort the sessions by their end times and then select sessions greedily.

inputFormat

The first line contains an integer n, the number of sessions. Each of the next n lines contains two integers representing the start and end times of a session, respectively.

outputFormat

Print a single integer representing the maximum number of non-overlapping sessions that can be attended.## sample

4
1 3
2 4
3 5
6 8
3