Problems > Three That Sum to T

Three That Sum to T

Difficulty: 1500 3500 ms 128 MB

sorting two-pointers

Do three DIFFERENT positions exist with ai + aj + ak = T?

Input: the first line has N and T; the second line has N integers.

Output: YES or NO.

Constraints:

  • 3 ≤ N ≤ 2000
  • |ai|, |T| ≤ 109

Sample Tests

Input 1
5 9
2 7 4 1 5
Output 1
NO
Input 2
3 100
1 2 3
Output 2
NO

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.