#C7875. Count Pairs With Sum
Count Pairs With Sum
Count Pairs With Sum
You are given an array of integers and a target integer ( k ). Your task is to count the number of pairs ( (i, j) ) such that ( i < j ) and ( a_i + a_j = k ). This is a typical hashing problem where the goal is to efficiently count the number of pairs meeting the specified condition.
For example, if the array is [1, 2, 3, 4, 3] and ( k = 6 ), the valid pairs are ( (2, 4) ) and ( (3, 5) ), so the answer is 2.
inputFormat
The first line of input contains a single integer ( n ) representing the number of elements in the array. The second line contains ( n ) space-separated integers representing the array elements. The third line contains an integer ( k ), the target sum.
outputFormat
Output a single integer representing the number of distinct pairs ( (i, j) ) with ( i < j ) such that their sum equals ( k ).## sample
5
1 2 3 4 3
6
2