题解 | 数对计数
数对计数
https://www.nowcoder.com/practice/7d05171e7e0e4c6086be233769e01d94
import sys
from collections import Counter
N,C = map(int,input().split())
lst = list(map(int,input().split()))
#num_count为每个数出现的次数,key为num val为count
num_count=Counter(lst)
#计算满足条件的数对
result = 0
for num in num_count:
target = num+C
if target in num_count:
#对满足条件的数对排列组合
result+=num_count[num]*num_count[target]
print(result)