#K2366. Max Possible Score
Max Possible Score
Max Possible Score
You are given a total of \(n\) problems, and a participant can attempt at most \(m\) problems. Each problem \(i\) has a score \(p_i\). The goal is to maximize the total score by selecting at most \(m\) problems. Mathematically, if the scores of the problems sorted in descending order are \(p_1, p_2, \dots, p_n\), then the maximum possible score is \(\sum_{i=1}^{m} p_i\).
Your task is to implement a program that reads the values of \(m\), \(n\) and the list of scores, and then outputs the maximum possible score by selecting the \(m\) highest scores.
inputFormat
The input is given via standard input (stdin) and contains two lines:
- The first line contains two space-separated integers, \(m\) and \(n\), where \(m\) is the maximum number of problems that can be attempted and \(n\) is the total number of problems.
- The second line contains \(n\) space-separated integers representing the score of each problem.
outputFormat
Output a single integer to standard output (stdout), which is the maximum possible score computed by summing up the top \(m\) scores.
## sample3 5
8 20 15 10 5
45
</p>