Sum of
k-largest numbers
Desing and implement a program that given n numbers, it will show the sum of
the first k largest numbers.
Input:
You will be given two integers:
1<=n<=1000 which will represent the number of numbers, and an
integer 1<=k<=n which will show how many numbers to add. Then you will be
given n space separated integers between 1 and 5000.
Output:
Show the sum of the k-largest numbers in one line.
Samples:
|
Input
|
Output
|
Test 1
|
7 2
5 6 2 1 3 6 7
|
13
|
Test 2
|
10 3
2 17 4 14 12 14 17 16 16 9
|
50
|