#C3220. Count Pairs with Sum
Count Pairs with Sum
Count Pairs with Sum
You are given an array of integers and an integer ( k ). Your task is to count the number of unique pairs ( (i, j) ) (with ( i < j )) such that the sum of the two numbers is equal to ( k ).
A pair is defined by two distinct indices in the array. Note that the pair ( (i, j) ) is considered the same as ( (j, i) ).
Examples:
Example 1: For the array [1, 2, 3, 4, 3] with ( k = 6 ), the valid pairs are (2, 4) and (3, 5) (using 1-indexed positions) which gives the output 2.
Example 2: For the array [1, 1, 1, 1] with ( k = 2 ), there are 6 valid pairs.
inputFormat
The first line of input contains two space-separated integers ( n ) and ( k ), where ( n ) denotes the number of elements in the array. The second line contains ( n ) space-separated integers representing the elements of the array.
outputFormat
Output a single integer representing the number of unique pairs whose sum is equal to ( k ).## sample
5 6
1 2 3 4 3
2
</p>