题解 | 小红的整数配对

小红的整数配对

https://www.nowcoder.com/practice/66b9810e4fe34956a8d1f5c67aacc6dc

n, k = map(int, input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
g = 0
s = 0
for i in range(len(a)-1):
    if g == 0:
        if a[i] - a[i+1] <= k:
            s += a[i] * a[i+1]
            g += 1
    else:
        g = 0
print(s)

    

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

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