#C5155. Minimum Problems to Achieve Target Score
Minimum Problems to Achieve Target Score
Minimum Problems to Achieve Target Score
In this problem, you are given ( n ) problems and a target score ( M ). Each problem has a specific score. Your task is to find the minimum number of problems that must be solved to accumulate a total score of at least ( M ). The strategy is to always choose the problems with the highest scores first. If it is impossible to reach ( M ) even after solving all the problems, output -1.
inputFormat
The input is given via standard input (stdin). The first line contains two integers ( n ) and ( M ), where ( n ) is the number of problems and ( M ) is the target score. The second line contains ( n ) space-separated integers representing the scores of each problem.
outputFormat
Output a single integer on standard output (stdout): the minimum number of problems required to reach at least the target score ( M ). If it is impossible, output -1.## sample
5 15
5 3 9 7 2
2