#JP29. 接豆子

接豆子

Problem Description

In a 2D Cartesian coordinate system, there are nn beans, where the ii-th bean has coordinates (xi,yi)(x_i, y_i).

Define a black hole as a segment parallel to the xx-axis with a length of kk. Specifically, if k=0k = 0, the black hole becomes a single point.

After the game starts, all the beans will continuously move in the negative yy-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 c,Tc, T, representing the test case ID and the number of test cases.

For each of the TT test cases:

  • The first line contains two positive integers n,kn, k, the number of beans and the length of the black hole.
  • The next nn lines each contain two integers xi,yix_i, y_i, 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 (0,0)(0,0) and (4,1)(4,1), as shown in the diagram below:

Diagram

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:

  • 1T51 \le T \le 5
  • 1n1051 \le n \le 10^5
  • 0k1090 \le k \le 10^9
  • 1xi,yi1091 \le x_i,y_i \le 10^9
Test ID nn \le kk \le xi,yix_i,y_i \le Special Properties
11 1010 No
232 \sim 3 10510^5 00 10910^9
454 \sim 5 10910^9 Yes
676 \sim 7 10310^3 No
8108 \sim 10 10510^5 10910^9

Special Properties:Number of different xx-coordinates 3\le 3.

Attachment Download

link