#K71917. Find Unique Pairs with Given Sum

    ID: 33638 Type: Default 1000ms 256MiB

Find Unique Pairs with Given Sum

Find Unique Pairs with Given Sum

Given an array of integers and a target value \(T\), your task is to find all unique pairs of numbers in the array that sum up to \(T\). Each valid pair must be represented as an array of two elements, with the smaller number first and the larger number second.

The list of pairs should be sorted in ascending order by the first element of each pair. Pairs are considered unique regardless of the order in which they appear in the input.

For example, if the input array is [2, 4, 3, 5, 7, 8, 1, 6] and \(T = 9\), the output should be [[1, 8], [2, 7], [3, 6], [4, 5]].

inputFormat

The input is given via standard input (stdin) and has the following format:

  • The first line contains an integer \(N\), the number of elements in the array.
  • The second line contains \(N\) space-separated integers representing the array elements.
  • The third line contains the target integer \(T\).

outputFormat

Output the list of unique pairs in JSON array format to standard output (stdout). Each pair should be displayed as an array of two integers. If no valid pair exists, output an empty array [].

## sample
8
2 4 3 5 7 8 1 6
9
[[1, 8], [2, 7], [3, 6], [4, 5]]