Diamond Collector (Bronze)
InterviewTime limit2sMemory limit512 MB
Choose the largest group of diamonds whose sizes differ by at most K.
- Level
Easy3 of 10
- Topics
- Sorting, Sliding window
- Solved
- No attempts yet
Problem
Bessie the cow likes shiny things, so she mines diamonds in her spare time. She has collected diamonds of varying sizes, and she wants to put some of them in a display case in the barn.
The diamonds in the case have to be similar in size, so Bessie will not put two diamonds in the case when their sizes differ by more than . Two diamonds whose sizes differ by exactly can be displayed together. Given , find the largest number of diamonds Bessie can put in the case.
Input
The first line contains and (, ).
Each of the next lines contains the size of one diamond. Every size is a positive integer no larger than .
Output
Print the largest number of diamonds that Bessie can put in the case, on one line.