世上只有一种英雄主义,就是在认清生活真相之后依然热爱生活。
It is winter now, and Max decided it's about time he watered the garden.
The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned on, then after one second has passed, the bed xi will be watered; after two seconds have passed, the beds from the segment [xi - 1, xi + 1] will be watered (if they exist); after j seconds have passed (j is an integer number), the beds from the segment [xi - (j - 1), xi + (j - 1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [xi - 2.5, xi + 2.5] will be watered after 2.5seconds have passed; only the segment [xi - 2, xi + 2] will be watered at that moment.
The garden from test 1. White colour denotes a garden bed without a tap, red colour — a garden bed with a tap.
The garden from test 1 after 2 seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour — a watered bed.
Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!
Input
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 200).
Then t test cases follow. The first line of each test case contains two integers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n) — the number of garden beds and water taps, respectively.
Next line contains k integers xi (1 ≤ xi ≤ n) — the location of i-th water tap. It is guaranteed that for each condition xi - 1 < xiholds.
It is guaranteed that the sum of n over all test cases doesn't exceed 200.
Note that in hacks you have to set t = 1.
Output
For each test case print one integer — the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.
Example
input
Copy
3 5 1 3 3 3 1 2 3 4 1 1
output
Copy
3 1 4
Note
The first example consists of 3 tests:
- There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered.
- There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes.
- There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4
#include
#include #include #include #include #include #include #include #include #include #include The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is rr units.
Some very rich customers asked him to complete some projects for their companies. To complete the ii-th project, Polycarp needs to have at least aiai units of rating; after he completes this project, his rating will change by bibi (his rating will increase or decrease by bibi) (bibi can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.
Polycarp can choose the order in which he completes projects. Furthermore, he can even skip some projects altogether.
To gain more experience (and money, of course) Polycarp wants to choose the subset of projects having maximum possible size and the order in which he will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.
Your task is to calculate the maximum possible size of such subset of projects.
Input
The first line of the input contains two integers nn and rr (1≤n≤100,1≤r≤300001≤n≤100,1≤r≤30000) — the number of projects and the initial rating of Polycarp, respectively.
The next nn lines contain projects, one per line. The ii-th project is represented as a pair of integers aiai and bibi (1≤ai≤300001≤ai≤30000, −300≤bi≤300−300≤bi≤300) — the rating required to complete the ii-th project and the rating change after the project completion.
Output
Print one integer — the size of the maximum possible subset (possibly, empty) of projects Polycarp can choose.
Examples
input
Copy
3 4 4 6 10 -2 8 -1
output
Copy
3
input
Copy
5 20 45 -6 34 -15 10 34 1 27 40 -45
output
Copy
5
input
Copy
3 2 300 -300 1 299 1 123
output
Copy
3
#include
#include #include #include #include #include #include #include #include #include #include Recently n students from city S moved to city P to attend a programming camp.
They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.
i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea.
For each student determine the second he will use the teapot and get his tea (if he actually gets it).
Input
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000).
Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students.
Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea.
It is guaranteed that for every condition li - 1 ≤ li holds.
The sum of n over all test cases doesn't exceed 1000.
Note that in hacks you have to set t = 1.
Output
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
Example
input
Copy
2 2 1 3 1 4 3 1 5 1 1 2 3
output
Copy
1 2 1 0 2
Note
The example contains 2 tests:
- During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second.
- During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
#include
#include #include #include #include #include #include #include #include #include #include