#C2584. Find Pairs with Sum

    ID: 45916 Type: Default 1000ms 256MiB

Find Pairs with Sum

Find Pairs with Sum

Given an array of integers and a target sum, your task is to identify all distinct pairs of numbers ((a, b)) (with (a \leq b)) such that (a + b) equals the target sum. Each valid pair should be printed on a separate line in ascending order based on the first element. If there is no such pair, output the string "No pairs found".

Note: Each pair must be unique. For example, even if the same pair can be formed in multiple ways from the input array, it should only be printed once.

inputFormat

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

  1. The first line contains an integer (n), the number of elements in the list.
  2. The second line contains (n) space-separated integers representing the list.
  3. The third line contains an integer representing the target sum.

outputFormat

For each unique pair ((a, b)) with (a \leq b) whose sum is equal to the target, print a line in the format: a b. The pairs should be printed in ascending order based on the first number of each pair. If no valid pair is found, output exactly "No pairs found".## sample

6
1 5 -1 4 2 -4
0
-4 4

-1 1

</p>