Can there be an alternate allocation of 30,20 books to one student and 10,40 to other?

In this case, we are getting the minimum allocated as 50

the order of books matters here. so you can not change the order of books given in input.
thanks