Two Pointers Sum
Given a sorted array of N distinct integers and a target integer S, find if there exist two distinct elements in the array that sum up to S. If multiple pairs exist, print any one of them. If no such pair exists, print -1 -1.
Input
The first line contains an integer N, the number of elements in the array. The second line contains N space-separated integers, the elements of the sorted array. The third line contains the target integer S.
Output
Print two space-separated integers, the indices of the two elements that sum up to S. If no such pair exists, print -1 -1.
Constraints
1 <= N <= 1000 -10^9 <= array elements <= 10^9 -2 * 10^9 <= S <= 2 * 10^9 The array is sorted in non-decreasing order and contains distinct integers.
Example 1
5 1 2 4 7 9 6
1 2
The pair (1, 4) at indices 1 and 2 sums to 6.
Example 2
4 -3 0 1 5 2
0 3
The pair (-3, 5) at indices 0 and 3 sums to 2.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
5 1 2 4 7 9 6
4 -3 0 1 5 2