8546: Buy Figurines

内存限制:128 MB 时间限制:6 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

During the "Hues of the Violet Garden" event, As the professional Lady Guuji hired, Sayu is assigned to buy one of the figurines, that is "Status of Her Excellency, the Almighty Narukami Ogosho, God of Thunder".

There are n people numbered from 1 to n who intent to buy a figurine and the store has mm windows with mm queues identified from 1 to mm. The ith person has an arrival time ai and a spent time si to buy a figurine(It guaranteed that everyone's arrival time a_iai is different). When a person arrives at the store, he will choose the queue with the least number of people to queue. If there are multiple queues with the least number of people, he will choose the queue with the smallest identifier. It should be noted that if someone leaves the queue at the same time, the person will choose the queue after everyone leaves the team.

Sayu has been here since last night so she could buy a figurine. But after waiting and waiting, her eyes started to feel real droopy and... overslept. If Sayu doesn't buy one of these figurines, the Tenryou Commission tengu will lock her up for life! The store will close after these n people buy figurines, that means she must wake up before the last one leaves. Now Lady Guuji wants to know the latest time Sayu wakes up.

For example, there are two people in the same line, a1=1,s1=2,a2=2,s2=2. When the first person arrives, there is no one in the line, so the start time and end time of purchasing the figurine are 1 and 3. When the second person arrives, the first person is still in line, so the start time and end time of purchasing the figurine are 3 and 5. And if the end time of the last person is x, the answer is x.

输入格式

The first line contains one integer T(1T10) .

The first line of each test case contains two positive integers n and m(1n2×105,1m2×105) --- the number of people and the number of queues.

Then, n lines follow, each consisting of two integers ai and si (1ai,si109) --- the arrival time and spent time of ii-th person.

It guaranteed that the sum of n does not exceed 2×106, and the sum of mm does not exceed 2×106.

输出格式

For each test case:

print a line containing a single integer --- the latest time Sayu wakes up, that means the end time of the last person.

输入样例 复制

1
5 3
2 4
1 3
5 1
3 4
4 2

输出样例 复制

7