Техника двух указателей

Triplet sum

Given an array A and a value of x. Find if there is a triplet (Ai, Aj, Ak) in array whose sum is equal to x. All indices i, j, k must be different.


The first line contains the size of array n (n104) and value of x (|x| ≤ 109). Second line cintains n integers, each no more than 109 by absolute value.


If such triplet is present in array, then print these three numbers in any order. If multiple triplets exist, print any. If such a triplet is not present in array, print -1.

Time limit 1 second
Memory limit 128 MiB
Input example #1
8 19
20 3 5 1 15 7 17 12
Output example #1
1 3 15
Author Michael Medvediev