HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Array and Matrices > problem:


030. 50737 - Sum of the k-largest numbers

Guest
• Discussion of problem (1)

Volume problems

• 50321 - Missing Number
• 50445 - Cryptography
• 50410 - Zero Padding
• 50380 - Sum of the Numbers in the ...
• 50400 - nth Row rth Element of a Table
• 50457 - The Number of Winners
• 50585 - Inner Product
• 50587 - Modular Conversion
• 030. 50737 - Sum of the k-larg...
• 50419 - The longest bitonic sequence
• 50317 - Student Line Up
• 50311 - Student Line Up
• 50398 - Sum of kth Anti-diagonal
• 50323 - Filtering Contact List
• 50364 - Student averages
• 50756 - Average of the Nth Student
• 50758 - National Elections - Revisited

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