oj mrJudge
Toggle navigation
  • Login
    • Forget Password
      Login
User Image

Hello, Stranger

Guest
  • Analysis Mode
  • Problems
    • All Problems
    • Latest Problems
  • Join Us Now
  • Registration
  • Contact Us
  • Infomation
  • About
    • Terms of Use
    • Technical Specifications
    • Credits

bananasmoothie Batch , stdin/stdout

Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

statement.html

Problem Statement

As some of his students are not eating their fruits, Rabbit had to bring them home. Thus, he now has N bananas.

Rabbit likes banana smoothies. Thus, he has decided to make them into banana smoothies. It takes K bananas to make a banana smoothie.

Bananas have different quality, which affect the banana smoothie. Each banana has quality Qi, and as Rabbit has very sensitive taste buds, the quality of a smoothie is given by the minimum quality of all bananas used to make the smoothie.

Rabbit wants to make some smoothies such that the sum of their quality is maximised. Help him find the maximum sum of the quality of the smoothies!

Input

The first line of input contains two integers, N and K.

The next line of input contains N integers, representing the array Q.

Output

The first and only line of output should contain a single integer denoting the maximum sum of the quality of the smoothies.

Limits

For all subtasks, 1 ≤ K ≤ N ≤ 100000 and -109 ≤ Qi ≤ 109.

Subtask 1 (10%): K = 1

Subtask 2 (30%): 0 ≤ Qi

Subtask 3 (60%): There are no more constraints.

Sample Input

8 3
9 2 3 4 2 3 -1 6

Sample Output

6

Explanation

We can make a smoothie using bananas 1, 4 and 8 (1-indexed) with quality 4 and another smoothie using bananas 2, 3 and 5 with quality 2. This adds up to 6, which is the maximum possible.

Tags

Greedy

Subtasks and Limits

Subtask Score #TC Time Memory Scoring
110121s256MBMinimum
23091s256MBMinimum
360351s256MBMinimum
4011s256MBMinimum

Judge Compile Command

g++-8 ans.cpp -o bananasmoothie -Wall -Wshadow -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512

Accepted Submissions

subIDUserTimeMax Time

Past Submissions

subIDUserTimeScore
mrJudge 09.05.20
Copyright © 2020 mrJudge. All rights reserved.