#C6179. Find Pair with Sum and Difference Constraints

    ID: 49910 Type: Default 1000ms 256MiB

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:

  1. An integer \( n \) representing the number of elements in the array.
  2. A line containing \( n \) space-separated integers representing the sorted array.
  3. 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.

## sample
5
1 2 3 4 6
8 1
True