Timer is Running

Mega Sale
Submissions: 5353   Accuracy:


  Difficulty: Basic   Marks: 1

Mr. Geek is a greedy seller. He has a stock of N laptops which comprises of both useful and useless laptops. Now, he wants to organize a sale to clear his stock of useless laptops. The prices of N laptops are Ai each consisting of positive and negative integers (-ve denoting useless laptops). In a day, he can sell atmost M laptops. Mr. Geek being a greedy seller want to earn maximum profit out of this sale. So, help him maximizing his profit by selling useless laptops.

The first line of input contains number of testcases T. For each testcase, there will be two lines of input. Th first line contains two integers N and M. The second line contains prices of N laptops.

The maximum profit Mr. Geek can earn in a single day.

1 <= T <= 30
1 <= N ≤ 105
1 <= M <= 105
-1012 <= Ai <= 1012

Sample Input:
4 3
-6 0 35 4
5 3
-1 -2 -3 -4 5

Sample Output:

Testcase 1:

Geek sells the laptops with price -6 and earns Rs. 6 as profit.
Testcase 2:
Geek sells the laptops with price -2, -3 and -4 and earns Rs. 9 as profit.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Siddharth Dungarwal
Author: sd5869

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.