#K45357. Find a Pair with a Given Sum

    ID: 27735 Type: Default 1000ms 256MiB

Find a Pair with a Given Sum

Find a Pair with a Given Sum

Given an array of integers and a target sum \(T\), your task is to find two distinct indices \(i\) and \(j\) such that \(arr[i] + arr[j] = T\). If such a pair exists, output the two indices separated by a space. If no such pair exists, output -1.

The input is given via standard input and the output should be printed to standard output. The solution must work efficiently even when the array contains negative numbers or duplicate values.

Note: If there are multiple valid pairs, output the first pair you find during a left-to-right scan of the array.

inputFormat

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

If a valid pair is found, output the two indices (0-indexed) separated by a space. Otherwise, output -1.## sample

4 9
2 7 11 15
0 1

</p>