#C8764. Find a Pair with Given Sum
Find a Pair with Given Sum
Find a Pair with Given Sum
You are given an integer n representing the number of elements in an array, followed by an integer K. Then, an array of n integers is provided.
Your task is to determine if there exist two distinct integers in the array whose sum is equal to K. If such a pair exists, output YES
; otherwise, output NO
.
The solution should read input from standard input (stdin) and write the answer to standard output (stdout).
Note: Two integers are considered distinct if they come from different positions in the array, even if they have the same value.
Mathematical formulation:
Given an array \(A = [a_1, a_2, \dots, a_n]\) and an integer \(K\), determine if there exist indices \(i\) and \(j\) with \(i \neq j\) such that:
\[ a_i + a_j = K \]inputFormat
The first line of input contains two integers n and K separated by a space, where:
- n is the number of elements in the array.
- K is the target sum.
The second line contains n integers separated by spaces representing the array elements.
outputFormat
Print YES
if there exists at least one pair of distinct integers whose sum equals K, otherwise print NO
. The output should be written to standard output.
5 6
1 3 4 2 5
YES