#K85377. Two Sum Indices
Two Sum Indices
Two Sum Indices
Given an array of integers and a target integer \(T\), your task is to find indices of two distinct elements such that their sum equals \(T\). More formally, find indices \(i\) and \(j\) (with \(i < j\)) such that
\(a_i + a_j = T\)
If such a pair exists, output the two indices separated by a space. Otherwise, output an empty tuple denoted by ()
.
Note: The answer is not necessarily unique; outputting any valid pair is acceptable.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- 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
Output the indices of the two numbers (0-indexed) that add up to \(T\) in ascending order, separated by a space. If no such pair exists, output ()
.
All output should be written to standard output (stdout).
## sample4 9
2 7 11 15
0 1
</p>