Two Pointers SumEasy

Two Pointers Sum

EasyPractice library · +10 XPtwo pointersarraystwo 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.

Time limit 1 s (native code; slower languages get more)Memory 256 MB14 hidden tests

Example 1

Input
5
1 2 4 7 9
6
Output
1 2

The pair (1, 4) at indices 1 and 2 sums to 6.

Example 2

Input
4
-3 0 1 5
2
Output
0 3

The pair (-3, 5) at indices 0 and 3 sums to 2.

Hints