F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Package Delivery

Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 3087    Accepted Submission(s): 841


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.
 

Sample Input
1 4 2 1 3 2 4 6 7 4 7
 

Sample Output
2
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 17:20:58, Gzip enabled