cswork / OA打开练习工作台

AmazonOA #94

Distinct Pairs of Stocks

估计简单可在线判题

考点(AI 标注)哈希计数

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.

输入格式

The first line contains n target (1≤n≤500000, 0≤target≤5×10⁹); the second line contains n profits (0..10⁹).

输出格式

Output a single integer answer.

样例 1

输入:

7 12
6 6 3 9 3 5 1

输出:

2

样例 2

输入:

1 12
6

输出:

0

样例 3

输入:

3 0
0 0 0

输出:

1

样例说明

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.