题解 | 小红的整数配对
小红的整数配对
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)
OPPO公司福利 1101人发布