#K91217. Find Indices With Target Sum
Find Indices With Target Sum
Find Indices With Target Sum
You are given an array of integers and a target integer. Your task is to find two distinct indices \(i\) and \(j\) such that the sum of the elements at these indices satisfies the equation:
$$a_i + a_j = \text{target}$$
If such a pair exists, output the two indices (0-indexed) separated by a space. If there are multiple possible answers, output the first valid pair found when scanning the array from left to right. If no such pair exists, print -1
.
Note: The input will be provided via standard input (stdin), and the output should be printed to standard output (stdout).
inputFormat
The first line contains two space-separated integers \(n\) and \(target\), where \(n\) is the number of elements in the array.
The second line contains \(n\) space-separated integers representing the elements of the array.
outputFormat
If a valid pair is found, output two space-separated integers representing the indices. If no such pair exists, print -1
.
5 6
1 2 3 4 5
1 3