题解 | 相差不超过k的最多数

相差不超过k的最多数

https://www.nowcoder.com/practice/562630ca90ac40ce89443c91060574c6

n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
left = 0
max_length = 0
for right in range(len(a)):
    while a[right] - a[left] > k:
        left += 1
    current_length = right - left + 1
    max_length = max(max_length,current_length)
print(max_length)

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务