BETA

#### Submissions: 301 Accuracy: 8.97%

Non-decreasing subsequence

Given a sequence of n integers, you have to find out the non-decreasing subsequence of length k with minimum sum. If no sequence exists output -1.

Input:

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains integers N and K where N denotes the size of the array and K is the subsequence length for which we have to find the minimum sum,

The second line of each test case contains N space separated integers denoting elements of the array A[ ].

Output:

Print the minimum sum for each test case in a new line. If no such answer exists print "-1".

Constraints:

1<= N <=1000

1<= K <=1000

1<= A[ ] <=100000

Example:

Input:

2

10 3

58 12 11 12 82 30 20 77 16 86

10 4

58 12 11 12 82 30 20 77 16 86

Output:

39

125

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

Contributor: Sujnesh Mishra

##### It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result: