#K45847. Two Sum Problem
Two Sum Problem
Two Sum Problem
You are given an array of integers and a target value \(T\). Your task is to find two distinct indices \(i\) and \(j\) such that:
\( \text{nums}[i] + \text{nums}[j] = T \)
If such a pair exists, print the two indices separated by a space. If no such pair exists, print -1.
You may assume that there is at most one solution for each input.
inputFormat
The input is read from standard input (stdin) with the following format:
- The first line contains two integers \(n\) and \(T\), where \(n\) is the number of elements in the array and \(T\) is the target sum.
- The second line contains \(n\) space-separated integers representing the array elements.
outputFormat
Print two space-separated integers representing the indices of the two numbers in the array that add up to \(T\). If no such pair exists, print -1.
## sample4 9
2 7 11 15
0 1