#C14626. Find Pair With Sum

    ID: 44296 Type: Default 1000ms 256MiB

Find Pair With Sum

Find Pair With Sum

You are given an array of integers and a target integer. Your task is to find two distinct indices i and j in the array such that the sum of the elements at these indices is equal to the target value. If such a pair exists, output the pair of indices (i, j); otherwise, output "-1 -1". The problem guarantees that each input will have at most one solution.

Note: The indices are zero-based. Use efficient approaches, as the array might be large.

We can express the problem mathematically as:

Find indices \(i\) and \(j\) with \(i \neq j\) such that \(a_i + a_j = T\), where \(a_i\) and \(a_j\) are elements of the given array and \(T\) is the target integer. If no such pair exists, output \((-1, -1)\).

inputFormat

The input is read from standard input (stdin) and has the following format:

  1. The first line contains an 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, representing the target sum.

outputFormat

The output should be written to standard output (stdout) and consist of two space-separated integers: the indices of the two numbers that add up to the target. If no such pair exists, output "-1 -1".## sample

4
2 7 11 15
9
0 1