Problem 107
Meeting Rooms
Easy · 10 pts · Array, Sorting
Problem
You are given N meetings, each as a time interval [start, end) that includes its start but not its end. Decide whether one person can attend all of them, meaning no two meetings overlap. A meeting that ends at time t does not overlap one that starts at time t. Sort the meetings by start time and check each pair of neighbours: if a meeting starts before the previous one ends, two meetings overlap and the answer is NO.
Input
First line: integer N. Next N lines: start and end of a meeting.
Output
Print YES or NO.
Constraints
1 <= N <= 10000; 0 <= start < end <= 1000000
Example input
3 0 30 5 10 15 20
Example output
NO
Explanation
The meeting [0, 30) runs while [5, 10) and [15, 20) take place, so the person cannot attend all of them. The answer is NO.