#C9433. Sum of k Largest Numbers
Sum of k Largest Numbers
Sum of k Largest Numbers
You are given a list of positive integers and an integer (k). Your task is to compute the sum of the (k) largest numbers in the list. In other words, if the sorted list in descending order is (a_1, a_2, \dots, a_n), you need to calculate
[ S = \sum_{i=1}^{k} a_i ]
This problem tests your ability to manipulate arrays and perform sorting operations efficiently.
inputFormat
The input is read from standard input (stdin). The first line contains space-separated positive integers representing the list. The second line contains a single positive integer (k), which specifies the number of largest elements to be summed.
outputFormat
Output to standard output (stdout) a single integer representing the sum of the (k) largest numbers in the list.## sample
1 3 5 7 9
3
21