#C14944. Count Pairs with Given Sum
Count Pairs with Given Sum
Count Pairs with Given Sum
Given a list of integers and an integer ( k ), count the number of distinct pairs ( (i, j) ) such that ( i < j ) and ( a_i + a_j = k ). Each pair must consist of two different indices and should only be counted once.
For example, for the list [1, 2, 3, 4] and ( k = 5 ), the valid pairs are (1, 4) and (2, 3), so the answer is 2.
inputFormat
The input is given via standard input (stdin) and consists of two lines.
The first line contains two integers: ( n ) (the number of elements in the list) and ( k ) (the target sum).
The second line contains ( n ) space-separated integers representing the list of numbers.
outputFormat
Output a single integer to standard output (stdout) which is the number of pairs that add up to ( k ).## sample
4 10
1 2 3 4
0