Mega Sale
Submissions: 3797   Accuracy:

18.98%

  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.

Input:
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.

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

Constraints:
1 <= T <= 100
1 <= N ≤ 107
1 <= M <= 107
-1018 <= Ai <= 1018

Sample Input:
1
4 3
-6 0 35 4

Sample Output:
6

Explanation:
Geek sells the laptops with price -6 and earns Rs. 6 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.