Loading...
Loading...
Loading...
Given n order amounts and a number k, print the total of the k largest amounts. Repeating max and remove k times is too slow when k is large.
Example
Input
5 2 40 15 90 27 63
Output
153
Try the problem first. Open one hint at a time.
Each max plus remove is O(n), and you repeat it k times.
Sort once, descending, then add the first k amounts.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor