This page is still under construction.

Parts of this page are still being built. What you see may change.

Meditation

Interview

Time limit1sMemory limit512 MB

Summary
Given n exercise grades, pick k distinct exercises so their sum is as large as possible.
Level

Easy2 of 10

Topics
Sorting, Greedy, Array
Solved
No attempts yet

Problem

Luna had a stressful day and wants to do a meditation routine that relaxes her well. Luna's routines are more or less relaxing, and to determine how relaxing a routine is, Luna computes its score. The higher the score, the more relaxing it is.

Luna graded each of the n exercises with a positive integer, and the score of a routine is simply the sum of the grades of its individual exercises. She gives you her list of graded exercises and asks you for the maximal grade of a routine composed of k different exercises.

Input

The first line of the input contains two space-separated integers: n and k. The n following lines each contain a single integer, the i + 1-th line containing the grade gi of the i-th exercise.

Output

The output should contain a single line with a single integer: the maximal score of a routine composed of k different exercises.

Constraints

  • 1 ≤ k ≤ n ≤ 100 000
  • for all 1 ≤ i ≤ n, we have 0 ≤ gi ≤ 10 000

Hint

We select the exercises 1, 2 and 5 which gives a total score of 10 + 22 + 10 = 42.

Examples1

  1. Example 1

    Input
    5 3
    10
    22
    7
    3
    10
    
    Expected output
    42