#C12934. Find Pairs with Sum
Find Pairs with Sum
Find Pairs with Sum
You are given an array of integers and a target sum \(T\). Your task is to find all unique pairs of integers from the array that add up to \(T\). Each pair must be output in ascending order and the overall list of pairs should be sorted in ascending order based on the first element of each pair. If no such pairs exist, output an empty list.
Input Format: The first line contains an integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers. The third line contains the integer target sum \(T\).
Output Format: Print the list of unique pairs in the form of a Python-style list of lists. Each pair should be in ascending order and the entire list should be sorted by the first element of each pair. If no valid pairs exist, print an empty list []
inputFormat
The input is given via standard input (stdin) in the following format:
- An integer \(n\) denoting the number of elements in the array.
- \(n\) space-separated integers representing the array elements.
- An integer \(T\) representing the target sum.
outputFormat
The output is printed to standard output (stdout) as a list of pairs. Each pair is represented as a list with two integers sorted in ascending order. The overall list of pairs is sorted in increasing order based on the first element of each pair. If no valid pairs exist, output an empty list: []
.
6
2 4 3 6 7 1
7
[[1, 6], [3, 4]]