#K56497. Minimum Triplet Sum
Minimum Triplet Sum
Minimum Triplet Sum
You are given an array of N integers and a target integer K. Your task is to find the minimum sum of any unique triplet (a, b, c) from the array such that:
\(a + b + c \ge K\)
If no such triplet exists, output -1
.
Note: A triplet is considered unique if it is composed of indices i, j, k
with i < j < k
.
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains two integers N and K separated by a space.
- The second line contains N integers separated by spaces.
outputFormat
Output a single integer representing the minimum sum of a triplet that satisfies \(a + b + c \ge K\). If no valid triplet exists, output -1
. The answer should be printed to stdout.
5 10
1 2 3 4 5
10