#K39712. 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 sum \(S\). Your task is to count the number of unordered pairs \((i, j)\) (with \(i < j\)) such that the sum of the elements \(a_i + a_j = S\).
Input Format:
The first line contains two space-separated integers \(n\) and \(S\) denoting the number of elements in the array and the target sum respectively. The second line contains \(n\) space-separated integers representing the elements of the array.
Output Format:
Output a single integer, the count of pairs in the array that sum up to \(S\).
Example:
For input:
4 6
1 5 7 -1
The output should be:
2
inputFormat
The first line contains two integers \(n\) (the number of elements) and \(S\) (the target sum).
The second line contains \(n\) space-separated integers representing the array.
outputFormat
Output a single integer representing the count of pairs with sum equal to \(S\>.
## sample4 6
1 5 7 -1
2