#C2282. Choose K Integers to Reach Target Sum
Choose K Integers to Reach Target Sum
Choose K Integers to Reach Target Sum
You are given an integer n and an array of n integers. You are also given two integers, k and m. Your task is to determine whether it is possible to choose exactly k integers from the array such that their sum is at least m. Formally, if you choose elements \(a_{i_1}, a_{i_2}, \ldots, a_{i_k}\), they must satisfy
\(\sum_{j=1}^{k} a_{i_j} \ge m\)
If such a selection is possible, output the chosen integers in descending order (separated by spaces). Otherwise, output -1
.
inputFormat
The input is given via standard input and consists of two lines:
- The first line contains three space-separated integers: n (n is the size of the array), k (the number of integers to choose), and m (the target sum).
- The second line contains n space-separated integers representing the elements of the array.
outputFormat
Output via standard output. If it is possible to choose k integers whose sum is at least m, print the chosen integers in descending order separated by spaces on one line. Otherwise, print -1
.
5 3 15
2 10 5 7 8
10 8 7
</p>