#C3131. Triplet Sum Problem: Find Three Numbers That Sum to Target

    ID: 46525 Type: Default 1000ms 256MiB

Triplet Sum Problem: Find Three Numbers That Sum to Target

Triplet Sum Problem: Find Three Numbers That Sum to Target

Given an array of integers and a target integer, determine whether there exist three distinct integers in the array that sum up exactly to the target.

You need to check if there exist indices i, j, and k (all distinct) satisfying

\(a_i + a_j + a_k = target\)

If such a triplet exists then output YES, otherwise output NO.

inputFormat

The input is given from stdin in the following format:

N target
a1 a2 a3 ... aN

Where:

  • N is the number of integers in the array.
  • target is the desired sum.
  • a1, a2, ..., aN are the integers of the array.

outputFormat

Print YES if there exists a triplet with a sum equal to the target value, otherwise print NO. The output must be written to stdout.

## sample
5 0 -1 2 1 -4 2
YES