#C7949. Pythagorean Triplet Finder

    ID: 51876 Type: Default 1000ms 256MiB

Pythagorean Triplet Finder

Pythagorean Triplet Finder

Given a list of positive integers and an integer \(K\), determine if there exist three distinct numbers \(a\), \(b\), and \(c\) from the list that form a Pythagorean triplet, i.e., satisfy \(a^2 + b^2 = c^2\) (in any order). Additionally, the triplet must meet at least one of the following conditions: either one of the numbers in the triplet is equal to \(K\), or the sum of the triplet equals \(K\).

Note that the list may contain duplicate elements; however, only distinct values should be considered when forming triplets.

Constraints:

  • \(1 \leq n \leq 1000\), where \(n\) is the length of the list.
  • \(1 \leq a, b, c \leq 1000\) for each element in the list.
  • \(1 \leq K \leq 3000\).

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

inputFormat

The input consists of two lines. The first line contains two integers (n) and (K), where (n) is the number of elements in the list. The second line contains (n) space-separated integers representing the list.

outputFormat

Output a single line containing YES if a valid Pythagorean triplet exists that meets the conditions, otherwise output NO.## sample

5 12
3 5 12 5 13
YES