#C2085. Minimum Exercises to Reach Target Benefit Score
Minimum Exercises to Reach Target Benefit Score
Minimum Exercises to Reach Target Benefit Score
You are given an integer n
indicating the total number of exercises, an integer t
representing the target benefit score, and a list of n
integers which denote the benefit scores of each exercise.
Your task is to determine the minimum number of exercises required such that the sum of their benefit scores reaches or exceeds the target t. Formally, find the smallest integer k (with 1 ≤ k ≤ n) such that
$$\sum_{i=1}^{k} benefits_i \ge t$$
If it is impossible to reach the target benefit score with the given exercises, output -1
.
inputFormat
The input consists of two lines:
- The first line contains two space-separated integers
n
andt
. - The second line contains
n
space-separated integers representing the benefit scores of each exercise.
outputFormat
Output a single integer representing the minimum number of exercises needed to achieve a total benefit score of at least t
. If it is not possible, print -1
.
5 9
3 4 4 2 1
3
</p>