#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int i = 0, j = 0, ans = 0;
while (j < n) {
// Since the array is sorted, calculate the difference directly
if (arr[j] - arr[i] <= k) {
ans = max(ans, j - i + 1); // Update the maximum length
j++; // Expand the window
} else {
i++; // Shrink the window
}
}
cout << ans;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKICAgIGludCBuLCBrOwogICAgY2luID4+IG4gPj4gazsKICAgIHZlY3RvcjxpbnQ+IGFycihuKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgY2luID4+IGFycltpXTsKICAgIH0KICAgIAogICAgaW50IGkgPSAwLCBqID0gMCwgYW5zID0gMDsKICAgIHdoaWxlIChqIDwgbikgewogICAgICAgIC8vIFNpbmNlIHRoZSBhcnJheSBpcyBzb3J0ZWQsIGNhbGN1bGF0ZSB0aGUgZGlmZmVyZW5jZSBkaXJlY3RseQogICAgICAgIGlmIChhcnJbal0gLSBhcnJbaV0gPD0gaykgewogICAgICAgICAgICBhbnMgPSBtYXgoYW5zLCBqIC0gaSArIDEpOyAvLyBVcGRhdGUgdGhlIG1heGltdW0gbGVuZ3RoCiAgICAgICAgICAgIGorKzsgLy8gRXhwYW5kIHRoZSB3aW5kb3cKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBpKys7IC8vIFNocmluayB0aGUgd2luZG93CiAgICAgICAgfQogICAgfQogICAgCiAgICBjb3V0IDw8IGFuczsKICAgIHJldHVybiAwOwp9Cg==