#C12852. Two Sum Pairs
Two Sum Pairs
Two Sum Pairs
Given an array of integers and a target sum \(S\), find all unique pairs of distinct numbers \( (a, b) \) such that \(a + b = S\) and \(a < b\). Each pair should be printed on a separate line, and the pairs must be sorted primarily by the first number and secondarily by the second number.
The solution should read input from standard input and print the result to standard output. If no valid pair exists, the program should not output anything.
inputFormat
The input is read from standard input and consists of three lines:
- The first line contains a single integer \(n\) representing the number of elements in the array.
- The second line contains \(n\) space-separated integers.
- The third line contains a single integer \(S\), the target sum.
outputFormat
For each unique pair of numbers that sum to \(S\) (with the smaller number first), output a line with two space-separated integers. If no pairs exist, output nothing.
## sample7
2 4 3 5 7 8 1
9
1 8
2 7
4 5
</p>