#C4322. Triplet Sum Finder
Triplet Sum Finder
Triplet Sum Finder
Given a sorted array of integers and a target value \(T\), determine whether there exists a triplet \(a, b, c\) in the array such that:
\(a + b + c = T\)
You are required to use an efficient approach (hint: the two-pointer technique) to solve this problem.
If such a triplet exists, output YES
; otherwise, output NO
.
inputFormat
The input is given in the following format from stdin:
N a1 a2 a3 ... aN T
Where:
- \(N\) is the number of elements in the sorted array.
- a1, a2, ..., aN represent the elements of the array.
- \(T\) is the target sum.
outputFormat
Output a single line to stdout containing YES
if there exists a triplet \(a, b, c\) with \(a+b+c = T\); otherwise, output NO
.
5
1 2 4 5 6
10
YES