#K33352. Find Pairs with Given Sum

    ID: 25068 Type: Default 1000ms 256MiB

Find Pairs with Given Sum

Find Pairs with Given Sum

You are given an array of integers and a target sum \(t\). Your task is to find all unique pairs \((a, b)\) from the array such that they satisfy the equation:

\(a + b = t\)

Each pair should be output with the two integers in increasing order, and the set of pairs should be sorted in lexicographical order (first by the first element then by the second element). If no such pair exists, output nothing.

Example:

Input:
7
1 2 3 4 3 2 5
5

Output: 1 4 2 3

</p>

inputFormat

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

  • 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

For each test case, output each unique pair on a separate line, with the two integers separated by a space. The pairs must be printed in lexicographical order based on their first, then second elements. If no valid pair exists, output nothing.

## sample
7
1 2 3 4 3 2 5
5
1 4

2 3

</p>