Pairs With a Given Sum
Count the pairs of positions i < j with ai + aj = K.
Input: the first line has N and K; the second line has N integers.
Output: the number of pairs summing to K.
Constraints:
- 1 ≤ N ≤ 105
- −109 ≤ ai, K ≤ 109
Sample Tests
Input 1
5 6 1 5 7 -1 5
Output 1
3
Input 2
4 0 0 0 0 0
Output 2
6
Discussion (opens after you solve — no spoilers before)
No comments yet.