TopCoder

餘切
owoovo is 8

User's AC Ratio

88.9% (16/18)

Submission's AC Ratio

71.0% (22/31)

Tags

Description

N 塊蛋糕,經過你審慎評估後,你了解到對於第 i 塊蛋糕他的好吃度為 yi。但無奈的是由於你食量有限,你只能吃下 K 塊蛋糕。

試問在最佳策略下,若要最大化吃下的蛋糕好吃度總和,這個總和最大可以是多少?

Input Format

輸入首行有兩個正整數 N,K,代表蛋糕的個數以及你能吃下的蛋糕數量。

接下來一行 N 個正整數 y1,y2,,yN,其中 yi 代表第 i 塊蛋糕的好吃度。

  • 1KN2×105
  • 1yi109

Output Format

輸出一行一個正整數,代表最大可能的蛋糕好吃度總和。

Sample Input 1

5 3
3 1 4 1 5

Sample Output 1

12

Sample Input 2

6 2
2 7 1 8 2 8

Sample Output 2

16

Hints

Problem Source

程式解題社教學題。

Subtasks

No. Testdata Range Constraints Score
1 0~1 範例測資。 0
2 0~8 無特別限制。 100

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 524288 65536 1 2
1 1000 524288 65536 1 2
2 1000 524288 65536 2
3 1000 524288 65536 2
4 1000 524288 65536 2
5 1000 524288 65536 2
6 1000 524288 65536 2
7 1000 524288 65536 2
8 1000 524288 65536 2