#C7344. Count Pairs with Given Sum
Count Pairs with Given Sum
Count Pairs with Given Sum
You are given an integer array and a target sum. Your task is to count the number of unique pairs ( (i,j) ) (with ( i < j )) such that ( arr[i] + arr[j] = target ).
The formula for each valid pair is given by: $$arr[i] + arr[j] = target$$.
Write a program that reads the input from standard input and outputs the number of such pairs to standard output.
inputFormat
The first line contains two integers ( n ) and ( target ), where ( n ) is the number of elements in the array. The second line contains ( n ) space-separated integers representing the array.
outputFormat
Output a single integer which is the number of unique pairs that sum to the target.## sample
5 6
1 5 7 -1 5
3