#K80027. Find Unique Pairs that Sum to a Target
Find Unique Pairs that Sum to a Target
Find Unique Pairs that Sum to a Target
You are given an array of integers and a target integer \(T\). Your task is to find all unique pairs \((a, b)\) from the array such that:
\(a + b = T\)
with the condition that \(a \le b\). The resulting pairs should be printed in ascending order based on the first element, and within each pair, the smaller number comes first.
If no such pair exists, output nothing.
Example:
Input: 6 5 1 2 3 4 3 2</p>Output: 1 4 2 3
Note: Each input instance begins with two numbers: the number of elements in the array and the target sum, followed by the array elements.
inputFormat
The input is provided from stdin in the following format:
n target a1 a2 a3 ... an
Where:
n
is the number of elements in the array.target
is the integer sum target \(T\).a1, a2, ..., an
are the integer elements of the array.
outputFormat
Print each unique pair that sums to the target on a separate line to stdout. Each line should contain two integers separated by a space. If no such pair exists, output nothing.
## sample6 5
1 2 3 4 3 2
1 4
2 3
</p>