题解 | 小红的整数配对
小红的整数配对
https://www.nowcoder.com/practice/66b9810e4fe34956a8d1f5c67aacc6dc
import sys
n,k=map(int,input().split())
a=list(map(int,sys.stdin.readline().split()))
a.sort()
res=0
i=n-1
while i>0:
if a[i]-a[i-1]<=k:
res+=a[i]*a[i-1]
i-=2
else:
i-=1
print(res)
查看7道真题和解析