AmazonOA #94
Distinct Pairs of Stocks
Estimated EasyJudge-ready
Topics (AI-labelled)Hashing
Count the unordered value pairs that can be formed from two distinct indices and sum to target. The same value pair counts only once; (a,a) requires at least two a.
Input
The first line contains n target (1≤n≤500000, 0≤target≤5×10⁹); the second line contains n profits (0..10⁹).
Output
Output a single integer answer.
Example 1
Input:
7 12
6 6 3 9 3 5 1
Output:
2
Example 2
Input:
1 12
6
Output:
0
Example 3
Input:
3 0
0 0 0
Output:
1
Example notes
Example 1: only (3,9) and (6,6), so the answer is 2. Example 2: a single 6 cannot pair with itself, so the answer is 0. Example 3: three 0s give three index pairs, but the only value pair is (0,0), so the answer is 1.
Editorial
Loading solution…