#C8319. Two Sum in a Sorted Array
Two Sum in a Sorted Array
Two Sum in a Sorted Array
You are given a sorted array of integers and a target integer \(T\). Your task is to find two distinct numbers in the array such that their sum equals \(T\), i.e. find indices \(i\) and \(j\) (with \(i < j\)) that satisfy:
[ \text{numbers}[i] + \text{numbers}[j] = T ]
The indices are 1-indexed. If such a pair exists, print the two indices separated by a space. If no such pair exists, print -1.
Note: The array is sorted in ascending order, and each test case is given via standard input. You must output your answer to standard output.
inputFormat
The input is read from standard input and consists of the following:
- An integer \(n\) denoting the number of elements in the array.
- A line containing \(n\) space-separated integers in ascending order.
- An integer \(T\) denoting the target sum.
outputFormat
If there exists a pair of numbers that add up to \(T\), output the two 1-indexed positions separated by a space. If no such pair exists, output -1.
## sample4
2 7 11 15
9
1 2