Thank you so much sir,
I understood the mistake and your post was very helpful as well.
Thanks sir for your reply.
I tried solving it but i keep getting WA for 4 different test cases(5 11 12 15)
I am not able to figure out which corner case i have missed.
The approach i have used is:
1)Sort both shelves in desc order
2)Compare all elements from the 0th index of the two shelves and find the first index where a shelf has an element greater than the other.
3)Keep two flags: flag2 for the shelf with highest element and flag for the other shelf.
4)Then I swap the last element of flag2 shelf with the first of flag shelf if it is greater .
5)Then i sort the flag shelf and skew is the sum of first elements of both shelves.
It fails for subtask 5 as well for which k=1.
I have 2 confusions in the problem.
1)Do we have to make exactly k swaps or at max k swaps?
2)If we swap one book from shelf 1 to shelf 2 can we swap that book again back to shelf 1 with some other book?