This page is still under construction.

Parts of this page are still being built. What you see may change.

Log Jumping

Time limit1sMemory limit128 MB

Summary
Find the largest set of equal-length logs that can be visited in a closed tour where jumps are allowed between logs whose segments share a point.
Level

Medium7 of 10

Topics
Intervals, Sorting, Graph
Solved
No attempts yet

Statement

The villagers keep a set of exercise facilities in the forest behind our village. One of them is made of many logs laid out along a straight trail. Every log has the same length and lies parallel to the trail.

"Log jumping" is a well-known game played there. It is a test of concentration whose goal is to step on as many logs as possible under the rules below.

  1. Choose any log and stand on it. Standing on a log counts as visiting it, and you may walk freely along the log you are currently on.
  2. Choose a log you have not visited yet and jump onto it. Every jump must be made in the direction perpendicular to the logs. Repeat this step as many times as you like.
  3. The last log you land on must be the log you started from. Except for that first-and-last log, each log may be visited at most once. The game ends as soon as you return to the starting log.

For example, suppose there are eight logs of length 55, numbered 11 to 88, as in the figure below. Starting on log 22 you may jump to log 44, then log 77, log 88, log 55, and finally back to log 22, visiting five logs in total. No route of this kind visits more than five logs, so the maximum here is five.

Given the length of the logs and the position of each log, help Ha-Jin find the largest number of logs she can visit. Two logs are reachable from each other whenever the horizontal segments they occupy share at least one point. In particular, if the right end of one log has the same coordinate as the left end of another, you may jump between the two in either direction. In the figure, for instance, you may jump between log 11 and log 44.

Input

The input is read from standard input. The first line contains the number of test cases TT. Each test case consists of two lines. The first line has two integers nn and kk, the number of logs and their common length (1≤n≤50001 \le n \le 5000, 1≤k≤1000001 \le k \le 100000). The second line has nn integers x1,x2,…,xnx_1, x_2, \ldots, x_n separated by single spaces, where xix_i is the x-coordinate of the left end of the ii-th log (−1000000≤xi≤1000000-1000000 \le x_i \le 1000000). Each log therefore occupies the segment from xix_i to xi+kx_i + k.

Output

Write to standard output. For each test case, print a single line containing the maximum number of logs that can be visited.

Examples6

  1. Example 1

    Input
    4
    8 5
    -4 4 -5 1 7 -3 4 7
    4 5
    -5 -4 -3 1
    2 10
    -1 5
    2 3
    -1 5
    
    Expected output
    5
    4
    2
    1
    
  2. Example 2

    Input
    1
    1 5
    0
    
    Expected output
    1
    
  3. Example 3

    Input
    1
    2 5
    0 5
    
    Expected output
    2
    
  4. Example 4

    Input
    1
    2 5
    0 6
    
    Expected output
    1
    
  5. Example 5

    Input
    1
    6 100
    0 10 20 30 40 50
    
    Expected output
    6
    
  6. Example 6

    Input
    1
    5 3
    0 3 6 9 12
    
    Expected output
    2