
Input: 'N' = 2, 'K' = 1
'L' = [4, 2]
'B' = [6, 8]
Output: 16
To maximize the cheese usage, Ninja can cut a second cake parallel to the side of length 8. So extra cheese needed will be 16.
The first line of input contains an integer ‘T', denoting the number of test cases.
For each test case, the first line contains two integers 'N' number of slices have and 'K' maximum number of slices Ninja can cut. Next, 'N' lines contain two integers, each stating the length and breadth of each slice.
For each test case, print an integer stating the maximum extra cheese needed to fill the newly formed boundaries in pizza.
Output for each test case will be printed in a separate line.
You don’t need to print anything. It has already been taken care of. Just implement the given function.
1 <= 'T' <= 10
1 <= 'N' <= 10^4
0 <= 'K' <= N
1 <= 'L[i]', 'B[i]' <= 10^4
Time Limit: 1sec
Each i-th slice has a length 'L[i]' and breadth 'B[i]'; we can cut it to divide it into two rectangles and maximize the perimeter of that slice.
We have to cut it parallel to X[i] = max(L[i], B[i]), and after that, the extra perimeter so formed will be Y[i] = 2 * X[i]. So we will store the extra perimeters given by each cake. After that, sort them and will pick the 'K' maximum cakes from.
Algorithm :