#K43047. Find Pair with Target Sum

    ID: 27222 Type: Default 1000ms 256MiB

Find Pair with Target Sum

Find Pair with Target Sum

Given an array of integers and a target integer \(T\), your task is to find two distinct numbers \(a\) and \(b\) in the array such that \(a + b = T\) and \(a \neq b\). If there are several valid pairs, output the pair with the smallest first number when arranged in ascending order. If no valid pair exists, output No valid pair found.

Note: The pair must consist of two different numbers (even if the same value appears more than once, you are not allowed to use the same value twice to form a pair). The answer should be printed as two numbers separated by a single space with the smaller number coming first.

Example:

Input:
50
10 20 10 40 50 60 70

Output: 10 40

</p>

inputFormat

The input is given via stdin as follows:

  • The first line contains the target integer T.
  • The second line contains a sequence of space-separated integers representing the array.

outputFormat

Print a single line to stdout containing either:

  • Two integers separated by a single space (the valid pair in ascending order) if such a pair exists, or
  • The string No valid pair found if no such pair exists.
## sample
50
10 20 10 40 50 60 70
10 40