#K4481. Three Numbers Sum Problem

    ID: 27614 Type: Default 1000ms 256MiB

Three Numbers Sum Problem

Three Numbers Sum Problem

You are given an array of integers and a target integer \(T\). Your task is to determine whether there exists a triplet \(a_i, a_j, a_k\) in the array such that

\(a_i + a_j + a_k = T\)

If such a triplet exists, output YES; otherwise, output NO. The problem requires you to consider only unique positions in the array (i.e. the indices of the three numbers should be distinct), though the same integer value may appear more than once in the array.

Note: If the size of the array is less than three, the answer is automatically NO.

inputFormat

The input is read from standard input (stdin) and consists of the following:

  1. The first line contains an integer \(n\) representing 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 an integer \(T\) which is the target sum.

outputFormat

Output to standard output (stdout) a single line containing either YES if a triplet exists whose sum equals the target, or NO if no such triplet exists.

## sample
6
12 3 4 1 6 9
24
YES