HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Sorting and sequences > problem:


50737 - Sum of the k-largest numbers

Guest
• Discussion of problem (1)

Section problems

• 50736 - Top N Donors - 2
• 50733 - The Highest Average
• 50364 - Student averages
• 50333 - Series of Squares
• 50734 - Product Info (In Srt)
• 50735 - Top M Products
• 50339 - The Largest Rectangle
• 50492 - Contest Scoreboard
• 50737 - Sum of the k-largest n...
• 50418 - Student averages
• 50875 - Take m-out
• 50748 - Gold Store
• 50766 - Word Puzzle
• 50741 - DNA Distance
• 50934 - Selling Cars
• 50746 - Most Visited
• 50509 - Reading Book

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