#C1620. Sum of Highest K Scores
Sum of Highest K Scores
Sum of Highest K Scores
You are given a list of n scores and an integer k. Your task is to compute the sum of the highest k scores.
Formally, let \(S = [s_1, s_2, \dots, s_n]\) be the list of scores. After sorting \(S\) in descending order, let \(S' = [s'_1, s'_2, \dots, s'_n]\). The answer is given by the formula:
\(\sum_{i=1}^{k} s'_i\)
It is guaranteed that \(1 \leq k \leq n\).
inputFormat
The input is read from standard input and consists of two lines:
- The first line contains two integers \(n\) and \(k\) separated by a space.
- The second line contains \(n\) integers representing the scores, separated by spaces.
outputFormat
Output a single integer, which is the sum of the highest \(k\) scores.
## sample5 3
10 50 20 40 30
120