#K68757. Count Pairs with Given Sum
Count Pairs with Given Sum
Count Pairs with Given Sum
You are given an array of integers and a target integer (k). Your task is to count the number of unique pairs ((a, b)) (with different indices) from the array such that (a + b = k). Note that if a number appears multiple times, each distinct pair is counted. For example, if the array is [1, 1, 1, 1] and (k = 2), there are (
\binom{4}{2} = 6) pairs.
Input constraints:
• The first line of input contains two integers: (n) (the number of elements in the array) and (k) (the target sum).
• The second line contains (n) integers separated by spaces.
Your solution should read from standard input (stdin) and write the result to standard output (stdout).
inputFormat
The input consists of two lines. The first line 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.
outputFormat
Output a single integer: the number of pairs in the array that sum up to (k).## sample
5 6
1 5 7 -1 5
3
</p>