


1. The array may contain duplicate elements.
2. The array can also contain negative integers.
3. Every element of the subsequence must be greater than or equal to the previous element.
The first line contains an integer T, which denotes the number of test cases or queries to be run. Then, the T test cases follow.
The first line of each test case contains two space-separated integers N and K, denoting the number of elements in the array and the length of the subsequence to be considered.
The second line of each test case contains N space-separated integers, representing the elements of the array.
For each test case, print in a new line, an integer denoting the maximum sum of an increasing subsequence of length K.
Print “-1” if no such subsequence exists.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 500
1 <= K <= N
-10^9 <= NUMS[i] <= 10^9
Where NUMS[i] represents the i-th element of the array.
Time Limit: 1 sec
After we are done with every such subsequence, we return the maximum sum.
This approach might exceed the time limit in most of the test cases.
Algorithm:
For any index i, DP[i][K] represents the maximum sum that a subsequence of size K ending at this index can have. We can get our answer by finding the maximum value amongst all DP[i][K].
Algorithm: