N, K = map(int, input().split())
diamonds = []
for i in range(N):
diamonds.append(int(input()))
diamonds.sort()
max_count = 0
# 왼쪽 시작점
for left in range(N):
# 오른쪽 끝을 left부터 끝까지 확인
for right in range(left, N):
# 크기 차이가 K를 넘으면 더 볼 필요 없음
if diamonds[right] - diamonds[left] > K:
break
count = right - left + 1
if count > max_count:
max_count = count
print(max_count)
To embed this project on your website, copy the following code and paste it into your website's HTML: