#JP29. 接豆子
接豆子
Problem Description
In a 2D Cartesian coordinate system, there are beans, where the -th bean has coordinates .
Define a black hole as a segment parallel to the -axis with a length of . Specifically, if , the black hole becomes a single point.
After the game starts, all the beans will continuously move in the negative -axis direction (i.e., downward).
You have two black holes, and you can place them anywhere (including at negative coordinates) to catch the beans. If at any moment a bean encounters a black hole, it is caught and stops moving. If a bean can never encounter a black hole, it is lost.
Your task is to design a placement strategy for the black holes to maximize the number of beans caught. Output the maximum number of beans caught.
Input Format
Read the data from the file bean.in
.
Each test contains multiple test cases.
The first line contains two positive integers , representing the test case ID and the number of test cases.
For each of the test cases:
- The first line contains two positive integers , the number of beans and the length of the black hole.
- The next lines each contain two integers , the coordinates of a bean.
Output Format
Output to the file bean.out
.
For each test case, output a single integer on a new line, representing the maximum number of beans that can be caught.
Samples
1 1
8 2
1 1
1 2
2 5
4 4
5 3
6 2
6 4
7 3
7
【Sample #1 Explanation】
The left endpoints of the two black holes can be positioned at and , as shown in the diagram below:
The red dots represent the beans that can be caught, totaling 7. This is one of the optimal solutions.
【Sample #2】
See the attached files bean/bean2.in
and bean/bean2.ans
。
This sample satisfies the properties of Test Case #1.
【Sample #3】
See the attached files bean/bean3.in
and bean/bean3.ans
。
This sample satisfies the properties of Test Case #2.
【Sample #4】
See the attached files bean/bean4.in
and bean/bean4.ans
。
This sample satisfies the properties of Test Case #4.
【Sample #5】
See the attached files bean/bean5.in
and bean/bean5.ans
。
This sample satisfies the properties of Test Case #6.
【Sample #6】
See the attached files bean/bean6.in
and bean/bean6.ans
。
This sample satisfies the properties of Test Case #8.
Constraints
For all data, it is guaranteed that:
Test ID | Special Properties | |||
---|---|---|---|---|
No | ||||
Yes | ||||
No | ||||
Special Properties:Number of different -coordinates .
Attachment Download
统计
相关
在下列比赛中: