#K83402. Two Sum Problem
Two Sum Problem
Two Sum Problem
Given an array of integers and a target integer \(k\), your task is to find two distinct indices \(i\) and \(j\) (0-indexed) such that:
\(a_i + a_j = k\)
If such a pair exists, output the two indices separated by a space. Otherwise, output -1.
It is guaranteed that each input has at most one valid answer.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains two integers \(n\) and \(k\) where \(n\) is the number of elements in the array and \(k\) is the target sum.
- The second line contains \(n\) space-separated integers representing the array elements.
outputFormat
Print to standard output (stdout) the two indices (0-indexed) separated by a space if a valid pair is found; otherwise, print -1.
## sample4 9
2 7 11 15
0 1