The things you own, end up owning you. It’s only after we’ve lost everything that we’re free to do anything.
Tyler Durden’s Fight Club has been restored by Shahriar. Let’s walk through it.
There are fighters numbered to . The strength of the th fighter is . In a battle between two fighters, the fighter with the higher strength will win. If the strength of the two fighters is equal, the fighter with the smaller number will win.
Of course, you do not talk about fight club. Besides, there are some new rules for the fight club as follows:
There will be fighting battles for days and people can bet on the fighters.
On the th day , anyone can bet on the th fighter where the th fighter, on that day, will fight with th fighters.
If th fighter wins a battle, the bettor will win taka (the currency of the fight club) and if the fighter loses, the bettor will lose taka.
The bettor can not bet for a single day or consecutively days. In other words, if a person bets on the th day, then the person has to bet on the th day and they can not bet on the th day.
Now, Sifat, one of the bettors, wants to bet for maximum days and you want to join the fight club. Shahriar will let you join if you can find the maximum amount of money (in taka) Sifat can win by betting not more than days.
The first line of the input contains an integer, denoting the number of test cases.
The first line of the each test case contains two integers, and denoting the number of fighters (battle days too) and number of maximum days Sifat will bet respectively.
The second line of the each test case contains space-separated integers denoting strength of each fighter.
It is guaranteed that sum of over all test cases will not exceed .
For each testcase, print an integer denoting the maximum amount of money (in taka) Sifat can win if he has no money initially.
Input | Output |
---|---|
3 1 1 12 5 5 7 5 1 3 3 4 2 10 121 1111 111 | 0 8 1 |
In the first test case, as there are only one fighter, no battle can happen, Sifat can’t win any money. In the second test case, by betting on st day, Sifat can win taka. As, he bets on st day, he has to bet on nd day and he can’t bet on rd day. So, by betting on nd day, he can win taka. Then, by betting on th day, he can win taka, by betting on th day (he bets on th day, so he has to bet on th day), he can’t won any money as no battle can happen and as th day doesn’t exist, it doesn’t matter. So, by betting in total days (which is less than given ) Sifat can win total taka. It can be shown that it is the maximum amount. In the third test case, Sifat bets on maximum days. So, by betting on nd and rd day, he can win maximum taka. |