#C2500. Find Pair with Sum

    ID: 45824 Type: Default 1000ms 256MiB

Find Pair with Sum

Find Pair with Sum

You are given an array of integers and a target sum \(T\). Your task is to find any pair of numbers from the array such that they add up exactly to \(T\). If such a pair exists, print the two numbers separated by a space; if no such pair exists, print -1.

Note: If there are multiple valid answers, you may output any one of them. Each input will contain only one test case.

For example:

  • Input: 4\n2 7 11 15\n9 produces Output: 2 7
  • Input: 4\n1 2 4 5\n8 produces Output: -1
  • Input: 4\n3 3 4 7\n6 produces Output: 3 3

inputFormat

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

  1. The first line contains a single integer \(n\), representing the number of elements in the array.
  2. The second line contains \(n\) space-separated integers representing the array elements.
  3. The third line contains a single integer \(T\), the target sum.

outputFormat

Print the pair of numbers that add up to the target sum separated by a space. If no such pair exists, print -1. The output is written to standard output (stdout).

## sample
4
2 7 11 15
9
2 7