#P7170. Package Delivery
Package Delivery
Problem Description
Little Q likes online shopping very much. In the next $10^9$ days, there will be $n$ packages delivered to the post office in total. Let's label the next $10^9$ days as day 1, day 2, $\dots$, day $10^9$ respectively. For the $i$-th package, it will arrive at the post office at day $l_i$, and the deadline to take it back home is day $r_i$, which means Little Q can take it back home at day $x$ if and only if $l_i\leq x\leq r_i$.
Every time Little Q comes to the post office, he can take at most $k$ packages together back home at the same time. Note that Little Q can go to the post office multiple times during a single day. Please help Little Q determine how to take these $n$ packages back home such that the number of times he will go to the post office is minimized.
Input
The first line contains a single integer $T$ ($1 \leq T \leq 3\,000$), the number of test cases. For each test case:
The first line contains two integers $n$ and $k$ ($1 \leq k\leq n \leq 100\,000$), denoting the number of packages and the number of packages Little Q can carry at the same time.
Each of the following $n$ lines contains two integers $l_i$ and $r_i$ ($1 \leq l_i\leq r_i \leq 10^9$), describing a package.
It is guaranteed that the sum of all $n$ is at most $1\,000\,000$.
Output
For each test case, output a single line containing an integer, denoting the minimum possible number of times that Little Q will go to the post office.
1
4 2
1 3
2 4
6 7
4 7
2