#K51162. Pair with Given Sum

    ID: 29027 Type: Default 1000ms 256MiB

Pair with Given Sum

Pair with Given Sum

You are given an array of integers and a target integer \(T\). Your task is to determine if there exist two distinct elements in the array such that their sum is exactly \(T\). In other words, if the array is \(a_1, a_2, \dots, a_n\), you need to check if there exist indices \(i\) and \(j\) (with \(i \neq j\)) such that \(a_i + a_j = T\).

If such a pair exists, output YES; otherwise, output NO.

Note: The array may contain duplicate values, but the two numbers chosen to form the sum must come from distinct positions in the array.

inputFormat

The input consists of three lines:

  1. The first line contains an integer (n) which is the number of elements in the array.
  2. The second line contains (n) space-separated integers representing the array elements.
  3. The third line contains a single integer (T), the target sum.

outputFormat

Output a single line containing YES if there exist two distinct elements in the array whose sum is equal to (T). Otherwise, output NO.## sample

5
1 2 3 7 8
10
YES

</p>