#C9782. Maximum Non-Overlapping Meetings

    ID: 53913 Type: Default 1000ms 256MiB

Maximum Non-Overlapping Meetings

Maximum Non-Overlapping Meetings

You are given a list of meetings, where each meeting has a start time and an end time. Your task is to determine the maximum number of meetings that can be scheduled in a single meeting room such that no two meetings overlap. Two meetings are considered non-overlapping if the start time of a meeting is not less than the end time of the previously scheduled meeting.

Formally, given a set of meetings \(\{(s_i, e_i)\}_{i=1}^{n}\), you need to select a maximum subset of meetings such that for every two consecutive meetings \((s_j, e_j)\) and \((s_k, e_k)\) in the subset, \(s_k \geq e_j\) holds.

Input: The first line contains an integer \(n\) representing the number of meetings. The next \(n\) lines each contain two space-separated integers representing the start and end times of a meeting.

Output: Print a single integer denoting the maximum number of non-overlapping meetings that can be scheduled.

inputFormat

The input is read from stdin in the following format:

n
s1 e1
s2 e2
... 
sn en

Where:

  • n is an integer representing the number of meetings.
  • Each subsequent line contains two integers si and ei representing the start and end times of the \(i\)-th meeting.

outputFormat

Print to stdout a single integer, which is the maximum number of non-overlapping meetings that can be scheduled.

## sample
3
1 2
3 4
0 6
2