#C5365. Count Pairs with Given Sum
Count Pairs with Given Sum
Count Pairs with Given Sum
You are given an array of integers and an integer ( k ). Your task is to count the number of pairs ((i, j)) with ( i < j ) such that the sum of the corresponding elements equals ( k ), i.e. ( a_i + a_j = k ).
Note: Each pair is considered only once regardless of the order.
inputFormat
The input is read from standard input (stdin) and consists of three parts:
1. An integer ( n ), representing the number of elements in the array.
2. A line with ( n ) space-separated integers, representing the elements of the array.
3. An integer ( k ) on a new line.
outputFormat
Output a single integer on standard output (stdout) denoting the number of pairs that sum up to ( k ).## sample
4
1 5 7 1
6
2