Meeting Room Assignment
Time limit2sMemory limit1024 MB
Pick the most meetings from N time intervals so that K rooms never overlap, where a room needs a gap of at least one time unit between meetings.
- Level
Medium6 of 10
- Topics
- Intervals, Dynamic programming, Sorting
- Solved
- No attempts yet
Problem
The Seoul City University Information Technology Building has meeting rooms, and meetings want to use them.
The room rules are as follows.
- Two or more meetings cannot run in the same room at the same time.
- A room needs time to be cleaned, so another meeting cannot start in the same room right when a meeting ends.
In other words, take two meetings and . Let and be their start times, and let and be their end times. The two meetings can share a room only if or .
Given the start time and end time of each of the meetings, find the maximum number of meetings that can use the rooms.
Input
The first line contains the number of meetings and the number of rooms .
From the second line through line , each line contains the start time and end time of a meeting, separated by a space. These are positive integers.
Output
Print the maximum number of meetings that can be held in the rooms.