#C12725. Two Sum in a Sorted Array

    ID: 42184 Type: Default 1000ms 256MiB

Two Sum in a Sorted Array

Two Sum in a Sorted Array

You are given a sorted list of integers in strictly increasing order and a target integer \(T\). Your task is to find two distinct indices \(i\) and \(j\) such that \(a_i + a_j = T\). If such a pair exists, output the indices (0-indexed) separated by a space; otherwise, output -1.

Constraints:

  • The list is sorted in increasing order.
  • If multiple pairs exist, output the one found by the two-pointer technique (i.e. the pair with the smallest left index encountered).

Input Format: The first line contains two integers \(n\) and \(T\), where \(n\) is the number of elements in the list. The second line contains \(n\) space-separated integers representing the sorted list.

Output Format: Print two integers representing the indices of the pair if they exist; otherwise, print -1.

inputFormat

The input consists of two lines:

  • The first line contains two integers \(n\) (the size of the list) and \(T\) (the target sum).
  • The second line contains \(n\) space-separated integers, representing a sorted list of integers.

outputFormat

Output a single line. If a pair exists such that their sum equals \(T\), print the two indices separated by a space. If no such pair exists, print -1.

## sample
5 9
1 2 3 4 5
3 4