xenny-and-questions

Today Xenny has an exam and he is reading the question paper. He has worked very hard for this and he absolutely knows everything. But there is one thing that he didn't practice and that is - writing speed.
Xenny is aware of this and is asking for your help. Xenny knows that he will definitely need 1 unit time for solving each question. Obviously, having studied so hard, he wants to maximize his marks. Your job is to tell him what are the maximum marks can he get if he chooses the right set of questions.
Formally, there are N questions in the paper. i^th  question carries ai marks. Tell Xenny the maximum marks he can get by correct selection of questions.

Hint: Use fast I/O methods.

Input:

The first line of input will contain an integer -  T, i.e. number of testcases.

T lines follow.

The format for each test case will be as follows:

First line will contain 2 space-separated integers - N, denoting the no. of questions and K, denoting the amount of time remaining in seconds.
Each of the next N lines contains an integer, where integer on i^th line denotes marks for i^th question.

Output:

For each testcase, print the maximum marks Xenny can get if he chooses the questions optimally.

(Assume Xenny solves every question he chooses correctly :P )

Constraints:

N ≥ 0

ai ≥ 0 for 0 ≤ i < N

SMALL:

1 ≤ T ≤1000, N ≤ 100, ai ≤ 100

MEDIUM:

1 ≤ T ≤ 100, N ≤ 1000,  ai ≤100000

LARGE:

1 ≤ T ≤ 100, N ≤ 100000, ai ≤100000

SAMPLE INPUT
2
3 3
1 2 3
2 1
3 4

SAMPLE OUTPUT
6
4

Source: hackerearth | Difficulty: EASY
Tags: Sorting

Greedy algorithms


Solutions:
t=int(input())

while t>0:
	temp=list(map(int,input().split()))
	n=temp[0]
	k=temp[1]

	arr=[]
	for i in range(0,n):
		q=int(input())
		arr.append(q)

	arr.sort(reverse=True)

	tot=sum(arr[:k])

	print(tot)
		
	t-=1