#C1153. Count Unique Pairs

    ID: 40856 Type: Default 1000ms 256MiB

Count Unique Pairs

Count Unique Pairs

You are given T test cases. For each test case, you are provided an integer n and an integer k on the first line, followed by a line with n integers representing the array. Your task is to determine the number of unique pairs of numbers \( (a, b) \) such that \( a+b=k \). A pair is considered unique if the numerical values are distinct regardless of the order (i.e. the pair \( (a, b) \) is the same as \( (b, a) \)).

Note: A valid pair requires that the two numbers come from different positions in the array. However, if the same number appears more than once and together they satisfy \( 2a = k \), then they can form a pair only once.

inputFormat

The first line of the input contains an integer T, the number of test cases. The description of each test case is as follows:

  • The first line of each test case contains two integers n and k where n is the number of elements in the array and k is the target sum.
  • The second line contains n space-separated integers representing the array.

All input is read from standard input (stdin).

outputFormat

For each test case, output a single integer denoting the number of unique pairs found, each on a new line. Output is to standard output (stdout).

## sample
3
5 7
1 2 3 4 5
5 10
1 1 1 1 9
4 0
1 -1 2 -2
2

1 2

</p>