Goldman SachsOA #31
Project Estimates
Estimated EasyJudge-ready
Topics (AI-labelled)Hashing
Given distinct project costs and a target difference, count the distinct unordered pairs of values whose absolute difference is exactly target.
Input
The first line contains n target (1≤n≤200000, 1≤target≤10^9); the second line contains n distinct positive integer costs (≤2×10^9). Following the original examples, this site sets the lower bound of n to 1.
Output
Output the number of unordered pairs of values whose absolute difference equals target.
Example 1
Input:
5 2
1 5 3 4 2
Output:
3
Example 2
Input:
3 2
1 3 5
Output:
2
Example 3
Input:
4 10
1 2 8 12
Output:
1
Editorial
Loading solution…