Problems > Pairs With a Given Sum

Pairs With a Given Sum

Difficulty: 1300 3000 ms 128 MB

implementation

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

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.