#K50172. Unique Pair Sums
Unique Pair Sums
Unique Pair Sums
Given a sorted sequence of integers and a target sum ( k ), the task is to count the number of unique pairs in the array such that the sum of the two numbers is exactly ( k ). Each pair ((a, b)) is considered unique by its values, meaning that if the same pair of numbers appears more than once, it should be counted only once. For example, given the array [1, 1, 1, 9, 9, 9] and ( k = 10 ), there is only one unique pair: (1, 9).
Note: The input array is guaranteed to be sorted in non-decreasing order and the number of elements ( n ) is at least 2.
inputFormat
Input is provided via standard input (stdin) in the following format:
( n ) ( k ) ( arr[0] ) ( arr[1] ) ... ( arr[n-1] )
where ( n ) is the number of elements in the sorted array, ( k ) is the target sum, and ( arr[i] ) represents the ( i^{th} ) element of the array. All values are separated by spaces.
outputFormat
Output a single integer to standard output (stdout) representing the total number of unique pairs whose sum equals ( k ).## sample
5 6 1 2 3 4 5
2