#C12476. Find Pairs That Sum to Target
Find Pairs That Sum to Target
Find Pairs That Sum to Target
Given a list of unique integers and a target integer (T), your task is to find all pairs ((a, b)) such that (a + b = T). Each pair must satisfy (a \le b), and the list of pairs should be sorted lexicographically. An efficient two-pointer technique can be used after sorting the array. Input is provided via standard input and the result should be printed to standard output.
For example, if the input is:
5 5 1 2 3 4 5
Then the valid pairs are:
(1, 4) and (2, 3), printed as:
1 4 2 3
inputFormat
The first line contains two integers (n) and (T), where (n) is the number of integers and (T) is the target sum. The second line contains (n) unique integers separated by spaces.
outputFormat
For each valid pair ((a,b)) that satisfies (a+b=T) (with (a \le b)), print a line with the two integers separated by a space. The pairs must be printed in lexicographical order. If no such pairs exist, print nothing.## sample
5 5
1 2 3 4 5
1 4
2 3
</p>