LearnToCP
Sign in
Navigation
HomeRoadmapProblemsAbout Us
Theory
Basics
Your First ProgramData types and IOC++ syntaxModuloFunctionsVectorsMatricesTime Complexity
Sorting
SortingCounting sortRadix Sort
Optimization Techniques
Two PointersSum of numbers 1 to nPrefix sumBinary SearchGreedyBinary Search Functions
Binary Numbers
Binary NumbersNumbers in codeBitwise Operations
Math
Binary ExponentiationPrime NumbersPrime FactorizationGCD and LCMSieve of Eratosthenes
Data Structures
StringsStackQueue
Dynamic Programming
About DPDP problems

Street Lamp

MediumProblem #14
Time LimitMemoryInputOutput
1 s64 MBstdinstdout

There are n houses in a street. The street is parallel to the x-axis and every house is given by its x coordinate. One street lamp of strength d should be placed on the street (at any point, not necessarily at a house): the lamp lights every house at distance at most d from it, both to the left and to the right.

Your task is to determine the largest number of houses that can be lit by a single lamp.

Input

The first line contains a single integer t - the number of testcases.

  • The first line of each testcase contains two integers n and d - the number of houses and the strength of the lamp.
  • The next line contains n integers - the x coordinates of the houses. Several houses can share the same coordinate.

Output

For every testcase print a single line with the largest number of houses one lamp can light.

Example

Input
2
6 13
29 -11 15 13 -68 -4
3 2
10 1 4
Output
4
2

In the first testcase a lamp at coordinate 2 lights the houses at −11,−4,13 and 15. In the second testcase a lamp between the houses at 1 and 4 lights both, but the house at 10 is out of reach.

Constraints

1≤t≤1000
1≤n≤2⋅105
−109≤xi​≤109
1≤d≤109
n1​+n2​+…+nt​≤2⋅105


This problem was adapted, with permission, from Svetiljka, authored by Društvo matematičara Srbije and Fondacija Petlja.

Submit your solution

Sign in to submit your solution and track your progress.

Sign in to submit