#K42987. Find Indices with Target Sum

    ID: 27209 Type: Default 1000ms 256MiB

Find Indices with Target Sum

Find Indices with Target Sum

Given an array of integers and a target integer \(T\), your task is to find two distinct indices \(i\) and \(j\) (using 1-based indexing) such that \(a_i + a_j = T\). If such a pair exists, output the indices in increasing order; otherwise, output -1.

The input is read from stdin and the output must be written to stdout.

inputFormat

The input consists of three lines:

  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, which are the array elements.
  3. The third line contains a single integer (T), the target sum.

outputFormat

If a valid pair of indices is found, output two space-separated integers indicating the 1-based indices of the two numbers. If no such pair exists, output -1.## sample

5
1 2 3 4 5
9
4 5