Capture as many as possible

There are n yachts in the ocean at different positions. You are looking at those yachts through stationary binoculars that can capture segments of length L. You’d like to look at as many yachts as possible.
Knowing that the yachts don’t currently move, what would be the maximum number of yachts you can look at simultaneously with those binoculars?
notion image


The first line of the input contains two integers n (1 ≤ n ≤ ) and L (1 ≤ L ≤ ).
The next line contains n integers () the positions of yachts.


The program should print the maximum number of yachts you can capture with stationary binoculars at once.


5 10 11 21 8 18 50


You can capture the yachts located at 8, 11, 18, or 11, 18, 21.


Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue