#K93772. Count Distinct Pairs with Given Sum
Count Distinct Pairs with Given Sum
Count Distinct Pairs with Given Sum
You are given an array of integers and an integer \( k \). Your task is to determine the number of unique pairs \( (i, j) \) such that \( i < j \) and \( arr[i] + arr[j] = k \). Two pairs are considered the same if they consist of the same pair of integers, regardless of their order.
Note: In cases where duplicate numbers are present, a valid pair is counted only once based on their values. For example, given the array [1, 1, 1] with \( k = 2 \), there is only one unique pair.
inputFormat
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 elements.
outputFormat
Output a single integer denoting the number of unique pairs whose sum equals ( k ).## sample
5 5
1 2 3 4 5
2