AmazonOA #122
Counting Pairs
估计简单可在线判题
考点(AI 标注)哈希计数
Count the distinct ordered value pairs (a,b) in the array such that a+k=b. The same index may serve as both a and b, so when k=0 every distinct value can pair with itself.
输入格式
The first line contains n k (2≤n≤200000, 0≤k≤10⁹), and the second line contains n numbers (0..10⁹).
输出格式
Output a single integer answer.
样例 1
输入:
4 1
1 1 1 2
输出:
1
样例 2
输入:
2 0
1 2
输出:
2
样例 3
输入:
4 2
1 3 5 7
输出:
3
样例说明
Example 1: only (1,2); the repeated 1 does not increase the answer, so the result is 1. Example 2: (1,1) and (2,2) are both valid, so the result is 2. Example 3: (1,3), (3,5), (5,7), so the result is 3.