#C5693. Maximizing Total Points
Maximizing Total Points
Maximizing Total Points
Chef is presented with N problems, each offering a certain number of points. He aims to maximize his total score by solving at most K problems. The problem is to select at most K problems from the list such that the sum of their points is maximized.
The mathematical formulation for the objective is to maximize:
\( S = \sum_{i=1}^{K} p_{i} \)
where \( p_{i} \) are the points of the selected problems after sorting the points in descending order.
Your task is to write a program that reads from stdin the input values and prints the maximum total points Chef can earn on stdout.
inputFormat
The first line of input contains two integers N and K separated by a space, where N is the total number of problems and K is the maximum number of problems Chef can solve. The second line contains N integers separated by spaces, representing the points for each problem.
outputFormat
Output a single integer representing the maximum total points Chef can obtain by solving at most K problems.## sample
7 3
4 8 15 16 23 42 8
81