Archive / 2022 / Final Round — Day 1
Two Spindles
Nimal and his group of friends are going to create a Vesak decoration. To create the Vesak decoration, they bought a set of N disks of different radii and two spindles. The decoration will be created by mounting disks on the spindles. But unfortunately, the maximum difference between the radius of any two disks in a spindle cannot exceed K. Nimal wants your support to know the maximum beauty value of the decoration so that he can show the decoration confidently to the public. The beauty value increases with the number of disks used therefore Nimal wants to know how many disks can be mounted to the two spindles. (Any number of disks can be mounted to a spindle while satisfying the conditions for the radii).
You have to help Nimal calculate the maximum number of disks that can be mounted.

Input Format
First Line: N K
Next N lines: radius of the ith disk
Output Format
A single integer denoting the maximum number of disks that can be mounted.
Constraints
- 1 \(\leq\) N \(\leq\) 106
- 1 \(\leq\) K \(\leq\) 109
- 1 \(\leq\) radius of each disk \(\leq\) 109
Limits
- Time Limit: 1s
- Memory Limit: 512MB
Sample Input 0
7 3
10
5
1
12
9
5
14
Sample Output 0
5
Open on HackerRank ↗ · Markdown source · Back to the archive