#C8657. Find Pair with Given Sum
Find Pair with Given Sum
Find Pair with Given Sum
You are given an array of n integers and a target integer \( T \). Your task is to find two distinct indices \( i \) and \( j \) (1-based) such that:
[ a_i + a_j = T ]
If such a pair exists, output the two indices separated by a space. If there are multiple solutions, you may output any one of them. If no such pair exists, output -1
.
Note: The array indices are 1-based.
inputFormat
The input is given from stdin in the following format:
- The first line contains an integer \( n \), the number of elements in the array.
- The second line contains \( n \) space-separated integers representing the array.
- The third line contains the target integer \( T \).
outputFormat
Output the indices of the two numbers that add up to the target, separated by a space. If no such pair exists, output -1
. The output should be printed to stdout.
5
2 7 11 15 3
9
1 2
</p>