题解 | #相差不超过k的最多数#
相差不超过k的最多数
https://www.nowcoder.com/practice/562630ca90ac40ce89443c91060574c6?tpId=308&tqId=2403293&ru=/exam/oj&qru=/ta/algorithm-start/question-ranking&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3D%25E7%25AE%2597%25E6%25B3%2595%25E7%25AF%2587%26topicId%3D308
import sys s = input().split() n = int(s[0]) k = int(s[1]) numbers = list(map(int,input().split())) numbers.sort() def findmax(numbers): ans=0 left=0 right=0 while right < n: if numbers[right]-numbers[left]<=k: ans=max(ans,right-left+1) right+=1 else: left+=1 return ans ans =findmax(numbers) print(ans)