#K43967. Find Pair with Given Sum
Find Pair with Given Sum
Find Pair with Given Sum
You are given an array of integers A and an integer X. Your task is to determine whether there exist two distinct elements in the array such that their sum equals X. In other words, you need to check if there exist indices i and j with i ≠ j such that:
\(A[i] + A[j] = X\)
If such a pair exists, output "Yes"; otherwise, output "No".
Note: The same element cannot be used twice unless it appears at least twice in the array.
inputFormat
The input is read from the standard input (stdin) with the following format:
- The first line contains an integer n, representing the number of elements in the array.
- The second line contains n space-separated integers, representing the array A.
- The third line contains an integer X, the target sum.
outputFormat
Output a single line to the standard output (stdout) with either "Yes" if there exist two distinct elements in the array whose sum is exactly X, or "No" if no such pair exists.
## sample4
10 15 3 7
17
Yes