244. Pairs That Add Up
Given n integers and a target t, print how many pairs of positions
(i, j) with i < j satisfy a[i] + a[j] == t.
Pairs of positions, not of values. In 2 2 2 2 with a target of 4, every one
of the six pairs of positions counts.
The obvious solution checks every pair, which is n(n-1)/2 comparisons. At
n = 200000 that is about twenty billion, and the largest test is sized so
that it will not finish. Sort first and the same question can be answered with
two pointers walking towards each other.
Constraints - `1 ≤ n ≤ 200000` - `-1000000000 ≤ a[i] ≤ 1000000000` - `-2000000000 ≤ t ≤ 2000000000`
Input
The first line contains two integers n and t.
The second line contains n integers in any order.
Output
Print one integer, the number of index pairs summing to t.
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.