#C12291. Unique Pair Sum Finder

    ID: 41702 Type: Default 1000ms 256MiB

Unique Pair Sum Finder

Unique Pair Sum Finder

You are given an array of integers and an integer target value \(T\). Your task is to find all unique pairs of numbers from the array whose sum equals \(T\). Each pair should be output in ascending order, and the overall list of pairs must be sorted in ascending order based on the first element of each pair. If no pairs are found, output an empty list.

Note: The solution must have a time complexity of \(O(n \log n)\) or better.

Example:

Input:
8
2 4 3 5 7 8 -1 1
6

Output: [(-1, 7), (1, 5), (2, 4)]

</p>

inputFormat

The input is read from standard input (stdin) and consists of three lines:

  1. An integer \(n\) representing the number of elements in the array.
  2. \(n\) space-separated integers representing the array elements.
  3. An integer \(T\) which is the target sum.

outputFormat

The output is a single line printed to standard output (stdout), which is the list of unique pairs that sum up to \(T\). Each pair is represented in the format (a, b) and the entire output is in list format. If no pair exists, output an empty list [].

## sample
8
2 4 3 5 7 8 -1 1
6
[(-1, 7), (1, 5), (2, 4)]