#C6179. Find Pair with Sum and Difference Constraints
Find Pair with Sum and Difference Constraints
Find Pair with Sum and Difference Constraints
Given a sorted array of integers in non-decreasing order, determine if there exists a pair of distinct elements that satisfies both of the following conditions:
- Their sum is equal to \( k \).
- Their absolute difference is greater than \( d \).
Formally, find two indices \( i \) and \( j \) (with \( i \neq j \)) such that
\[
nums[i] + nums[j] = k \quad \text{and} \quad |nums[i] - nums[j]| > d,
\]
where the array nums
is sorted in non-decreasing order. If such a pair exists, output True
; otherwise, output False
.
inputFormat
The input is given from stdin
as follows:
- An integer \( n \) representing the number of elements in the array.
- A line containing \( n \) space-separated integers representing the sorted array.
- A line containing two integers \( k \) and \( d \) separated by a space, where \( k \) is the target sum and \( d \) is the minimum required difference.
outputFormat
Print True
if there exists a pair satisfying the conditions; otherwise, print False
.
5
1 2 3 4 6
8 1
True