AmazonOA #122
Counting Pairs
Estimated EasyJudge-ready
Topics (AI-labelled)Hashing
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.
Input
The first line contains n k (2≤n≤200000, 0≤k≤10⁹), and the second line contains n numbers (0..10⁹).
Output
Output a single integer answer.
Example 1
Input:
4 1
1 1 1 2
Output:
1
Example 2
Input:
2 0
1 2
Output:
2
Example 3
Input:
4 2
1 3 5 7
Output:
3
Example notes
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.
Editorial
Loading solution…