#K74412. Two Sum Indices
Two Sum Indices
Two Sum Indices
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 equals the target, i.e., \(a_i + a_j = target\). If such a pair does not exist, output -1.
The problem can be formally stated as follows: Given an array \(A = [a_0, a_1, \dots, a_{n-1}]\) and an integer \(target\), find indices \(i\) and \(j\) (with \(i \neq j\)) such that:
[ a_i + a_j = target ]
If multiple valid pairs exist, return the first pair you encounter by scanning the array from left to right. Note that the input and output are handled via standard input (stdin) and standard output (stdout) respectively.
inputFormat
The first line contains two integers \(n\) and \(target\), where \(n\) is the number of elements in the array. The second line contains \(n\) space-separated integers representing the array elements.
outputFormat
If a valid pair is found, output two integers representing the indices (0-indexed) separated by a space. If no such pair exists, output -1.
## sample4 9
2 7 11 15
0 1