#C10994. Two Sum Indices
Two Sum Indices
Two Sum Indices
Given an array of n integers and a target sum target, your task is to find the two numbers in the array that add up exactly to the target. You are guaranteed that there is exactly one solution for each test case.
You should output the indices (1-based) of these two numbers. If the numbers at positions i and j (with i < j) are the correct pair, output them as "i j" separated by a space. The formula for the target can be expressed as: \(a_i + a_j = target\), where \(1 \leq i, j \leq n\) and \(i \neq j\).
Please note that input and output are provided via standard input and output (stdin and stdout) respectively.
inputFormat
The first line contains two integers n
and target
separated by a space, where n
is the number of elements in the array.
The second line contains n
space-separated integers representing the array.
outputFormat
Output two space-separated integers representing the 1-based indices of the two numbers that add up to target
.
4 9
2 7 11 15
1 2
</p>