Meetings
InterviewTime limit1sMemory limit1024 MB
Each person occupies an interval [Si, Ei]; pair up people whose intervals overlap into disjoint pairs and maximize the number of pairs.
- Level
Medium6 of 10
- Topics
- Greedy, Sorting, Intervals, Two pointers
- Solved
- No attempts yet
Problem
N people want to hold meetings. The i-th person stays in the meeting room from time Si to time Ei. If there is a moment when two people are in the meeting room at the same time, those two people can hold a meeting together. A person can be included in at most one meeting. You want to hold as many meetings as possible to improve work efficiency. Find the number of meetings that can be held.
Input
The first line gives N. (1 ≤ N ≤ 5 × 105)
Over N lines, Si and Ei are given, separated by a space. (For all i, 1 ≤ Si ≤ Ei ≤ 109)
Output
Print the maximum number of meetings that can be held.