After AC…
This problem can be simplified as only two Koalas are required. This is not exact solution but a hint towards solution
Step 1: Sort array by weight
Step 2: Keep track of maximum beauty as per new array
Step 3: Compute max beauty possible for each koala as a pair