#K53297. Two Sum Indices

    ID: 29500 Type: Default 1000ms 256MiB

Two Sum Indices

Two Sum Indices

Given an array of integers and a target integer, find two distinct indices \(i\) and \(j\) (with \(i < j\)) such that \(a[i] + a[j] = \text{target}\). If such a pair exists, output the indices; otherwise, output -1.

Note: All array indices are 0-indexed. If there are multiple valid solutions, output the first one found according to the natural order of iteration.

inputFormat

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

  • The first line contains two integers \(n\) and \(\text{target}\), where \(n\) is the number of elements in the array.
  • The second line contains \(n\) space-separated integers representing the array.

outputFormat

Output to standard output (stdout) a single line:

  • If there exists a pair of indices \(i\) and \(j\) (with \(i < j\)) such that \(a[i] + a[j] = \text{target}\), print the two indices separated by a space.
  • If no such pair exists, print -1.
## sample
4 9
2 7 11 15
0 1