Hide

Problem D
Classrooms

The new semester is about to begin, and finding classrooms for orientation activities is always a headache.

There are $k$ classrooms on campus and $n$ proposed activities that need to be assigned a venue. Every proposed activity has specfic starting time $s_ i$ and ending time $f_ i$. Any such an activity should take place at one of the classrooms. Any of the $k$ classrooms is big enough to hold any of the proposed activities, and each classroom can hold at most one activity at any time. No two proposed activities can take place at the same classroom at the same time. Even if two proposed activities overlap momentarily (the ending time of one activity equals the starting time another activity), they cannot be assigned to the same classroom.

There are so many proposed activities that there may not be enough classrooms to hold all the activities. It is desirable to have as many activities as possible. At most how many proposed activities can be assigned to the classrooms?

Input

  • The first line contains two positive integers $n$ and $k$ ($1 \leq k \leq n \leq 200\, 000$), representing the number of proposed activities and number of classrooms, respectively.

  • The following $n$ lines each contains two positive integers: the $i$th line among these $n$ lines contains $s_ i$ and $f_ i$ ($1 \leq s_ i \leq f_ i \leq 10^9$), indicating the starting time and ending time of proposed activity $i$.

Output

Output an integer indicating the maximum number proposed activities that can be scheduled.

Sample Input 1 Sample Output 1
4 2
1 4
2 9
4 7
5 8
3

Please log in to submit a solution to this problem

Log in