HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Sorting and sequences > problem:


50737 - Sum of the k-largest numbers

Guest
• Discussion of problem (1)

Section problems

• 50872 - Top M Grades
• 50868 - Sort Frequencies
• Trip to Librazhd
• 50912 - Trip to Librazhd
• 50914 - Buy 3, Pay 2
• 50732 - Sorting
• 50730 - The largest product
• 50731 - The largest product (2)
• 50737 - Sum of the k-largest n...
• 50492 - Contest Scoreboard
• 50320 - Random Sorted List
• 50738 - Median value
• 50317 - Student Line Up
• 50311 - Student Line Up
• 50736 - Top N Donors - 2
• 50333 - Series of Squares
• 50734 - Product Info (In Srt)

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