‘N’ = 2
‘K’ = 2
‘A’ = {2, 3, 1}
On the 1st date, they can go to restaurant 1 or restaurant 2.
On the 2nd date, they can go to restaurant 2 or restaurant 3.
The possible combination of restaurants:
‘1’ and ‘2’ on 1st date and 2nd date respectively = 2 + 3 = 5
‘1’ and ‘3’ on 1st date and 2nd date respectively = 2 + 1 = 3
‘2’ and ‘2’ on 1st date and 2nd date respectively = 3 + 3 = 6
‘2’ and ‘3’ on 1st date and 2nd date respectively = 3 + 1 = 4
Maximum Total number of coins = max(5, 3, 6, 4) = 6
The first line contains an integer ‘T’ which denotes the number of test cases to be run. Then the test cases follow.
The first line of each test case contains two integers, ‘N’ and ‘K’, denoting the number of dates and the number of restaurants they can go to on each date, respectively.
The second line contains (‘N’ + ‘K’ - 1) space-separated integers, where the ‘I-th’ integer denotes the number of coins to be spent in the ‘I-th’ restaurant.
Print a single integer representing the maximum total number of coins required for each test case.
Print the output of each test case in a new line.
You don’t need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= K <= N <= 10^5
1 <= ARR[i] <= 10^4
Sum of ‘N’ over all test cases is <= 10^5.
Time Limit: 1 sec
To calculate the maximum total number of coins for all the ‘N’ dates, we should calculate the maximum possible coins for each date and sum them up.
For Example :
‘N’ = 4, ‘K’ = 3, ‘A’ = {3, 4, 2, 1, 9, 1}
restaurant number 1, has maximum coins up to restaurant number 1.
restaurant number 2, has maximum coins up to restaurant number 4.
restaurant number 5, has maximum coins up to restaurant number 6.
Now, on the first date, the restaurant with the maximum coins is restaurant 2.
Restaurant number 2 will also remain the restaurant with maximum coins on the second date.
Then restaurant 5 will be the restaurant with maximum coins.
Algorithm :