#C6607. Pair Sum in a Sorted Array
Pair Sum in a Sorted Array
Pair Sum in a Sorted Array
You are given a sorted array of integers and a target integer value. Your task is to determine if there exists a pair of distinct elements in the array whose sum is exactly equal to the target.
Formally, given an array \(A = [a_1, a_2, \dots, a_n]\) and an integer \(T\), determine whether there exist indices \(i\) and \(j\) with \(i < j\) such that \[ a_i + a_j = T. \]
If such a pair exists, output 1
; otherwise, output 0
.
Note: The input array is given in non-decreasing order.
inputFormat
The first line of input contains two space-separated integers \(n\) and \(T\), where \(n\) is the number of elements in the array and \(T\) is the target sum.
If \(n > 0\), the second line contains \(n\) space-separated integers representing the sorted array. If \(n = 0\), the second line will be absent.
outputFormat
Output a single integer: 1
if there exists a pair whose sum is exactly \(T\), otherwise 0
.
5 5
1 2 3 4 6
1