钻石收藏家
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e4 + 10;
int a[N];
int main()
{
int n, k;
cin >>n >>k;
for(int i = 0; i < n; i ++)
{
cin >>a[i];
}
sort(a, a + n);
int mx = 0;
for(int i = 0; i < n; i ++)
{
int l = 0, r = n - 1;
while(l < r)
{
int m = (l + r + 1) >> 1;
if(a[m] - a[i] <= k) l = m;
else r = m - 1;
}
mx = max(l - i + 1 , mx);
}
cout << mx <<endl;
return 0;
}