Non-decreasing subsequence
##### Submissions: 662   Accuracy: 12.01%   Difficulty: Easy   Marks: 2

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
Author: sujnesh

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.