#K11036. Maximum Score Achievable
Maximum Score Achievable
Maximum Score Achievable
Nina is preparing for a programming contest and wants to maximize her score. Given n problems with their corresponding scores and her ability to solve at most m problems, she aims to achieve the highest possible total score.
Your task is to choose the m highest scoring problems out of the n available and sum their scores. More formally, if the scores are given as \(s_1, s_2, \dots, s_n\), then you need to compute \(\max \sum_{i=1}^{m} s_{i} \) after selecting the top m scores.
The input consists of two lines. The first line contains two integers \(n\) and \(m\). The second line contains \(n\) integers representing the scores for each problem. Your output should be a single integer representing the maximum score achievable.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains two integers \(n\) (the number of problems) and \(m\) (the maximum number of problems that can be solved), separated by a space.
- The second line contains \(n\) integers representing the scores for each problem, separated by spaces.
outputFormat
The output is written to standard output (stdout) and should be a single integer, representing the maximum total score that Nina can achieve by solving at most \(m\) problems.
## sample5 3
100 200 300 400 500
1200
</p>