#P1884C. Medium Design
Medium Design
Description
The array is initially filled with zeroes. You are given pairwise distinct segments . You have to select an arbitrary subset of these segments (in particular, you may select an empty set). Next, you do the following:
- For each , if the segment has been selected to the subset, then for each index you increase by (i. e. is replaced by ). If the segment has not been selected, the array does not change.
- Next (after processing all values of ), you compute as the maximum value among all elements of . Analogously, compute as the minimum value.
- Finally, the cost of the selected subset of segments is declared as .
Please, find the maximum cost among all subsets of segments.
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains two integers and (, ) — the number of segments and the length of the array.
The following lines of each test case describe the segments. The -th of these lines contains two integers and (). It is guaranteed that the segments are pairwise distinct.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output the maximum cost among all subsets of the given set of segments.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains two integers and (, ) — the number of segments and the length of the array.
The following lines of each test case describe the segments. The -th of these lines contains two integers and (). It is guaranteed that the segments are pairwise distinct.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output the maximum cost among all subsets of the given set of segments.
Note
In the first test case, there is only one segment available. If we do not select it, then the array will be , and the cost of such (empty) subset of segments will be . If, however, we select the only segment, the array will be , and the cost will be .
In the second test case, we can select all the segments: the array will be in this case. The cost will be .