#C5174. Maximum Non-overlapping Meetings

    ID: 48794 Type: Default 1000ms 256MiB

Maximum Non-overlapping Meetings

Maximum Non-overlapping Meetings

You are given a set of meetings, each defined by a start time and an end time. Your task is to determine the maximum number of meetings that can be attended without any overlap. Two meetings are considered non-overlapping if the start time of one meeting is greater than or equal to the end time of the other. Note that if a meeting ends at time \(t\) and another starts at time \(t\), they do not overlap.

Explanation: The problem is a classic scheduling problem. An optimal solution can be achieved by sorting the meetings by their end times and then iteratively selecting meetings that start after or exactly when the previous one ended.

Example:

Input:
3
1 3
2 4
3 5

Output: 2

</p>

inputFormat

The first line contains a single integer \(n\) which represents the number of meetings. The following \(n\) lines each contain two space-separated integers \(s\) and \(e\), representing the start and end times of each meeting respectively.

Constraints:

  • \(1 \leq n \leq 10^5\)
  • \(0 \leq s < e \leq 10^9\)

outputFormat

Output a single integer representing the maximum number of non-overlapping meetings that one can attend.

## sample
3
1 3
2 4
3 5
2

</p>