HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Array and Matrices > problem:


030. 50737 - Sum of the k-largest numbers

Guest
• Discussion of problem (1)

Volume problems

• 50792 - The student with the highest...
• 51182 - Count and Sum 2
• 51193 - The max element of k-th co...
• 51196 - The sum of two arrays
• 51197 - Even and odd Numbers
• Problem 3
• 50468 - Draw Matrix - 2
• 010. 50381 - Sum of the numbers
• 030. 50737 - Sum of the k-larg...
• 060. 50389 - Reverse an Array
• 100. 50330 - Find the average of n ...
• 110. 50359 - Mode of a Series
• 120. 50331 - Number of Numbers o...
• 120. 50329 - Draw Matrix-1
• 125. 50538 - Sum of kth Diagonal
• 140. 50599 - Sum of Squared Error ...
• 15-SprPrE1-80. 50741 - DNA Distance

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Question by Arnold Drita. Difficulty Alpha

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

 

Для отправки решений необходимо выполнить вход.

www.contester.ru