Given an array sequence [A1 , A2 ...An], the task is to find the maximum possible sum of increasing subsequence S of length K such that Si1<=Si2<=Si3.........<=Sin.

**INPUT**

The first line contains an integer 'T' denoting the number of testcases. Then 'T' test cases follows. Each test case consists of two line containing two space separated integers 'N' and 'K' denoting the size of the array and length of the subsequence.

**OUTPUT**

Print the maximum possible sum. If their is no subsequence of length K print "-1".

**CONSTRAINTS**

1 <= T <= 100

1 <= N <= 100

1 <= a[i] <= 10^5

1 <= k <=100

**Example**

**Input**

1

8 3

8 5 9 10 5 6 19 8

**Output**

38

**Explanation**

In sample input Possible Increasing subsequence of Length 3 with maximum possible sum is 9 10 19

Author: vaibhav2992

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.

jhasaurabh312 | 138 |

Aaaaarohiiii | 136 |

Harsha_kunchala | 128 |

tushki | 124 |

RajaRajput | 117 |

ARUN_PUNDIR | 617 |

manishgupta8497 | 607 |

Abhimanyu_kumar | 559 |

KhyatiSoneji | 501 |

Aman___Jain | 496 |

blackshadows | 5335 |

Ibrahim Nash | 5223 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.