Book Allocation

why s is taken the maximum number of pages in all books(40)?Why not 0 ?

because if the no of students is equal to no of books in that case each student has to read 1 book in that case the last student has to read maximum no of pages so that all books are read ( array is sorted ) so the search space starts from s = max of element in array since atleast 1 book is being read by the student

but if there are 4 students and each student is reading one book,and we have to take the minimum then why didn’t we take s=10 as the first student is reading only 10 pages

seee if each student just reads 10 pages then how would the entire 100 pages be completed

we need to ensure that all books are read completely by the no of students stated in question

why each student will read just 10 pages?they have assigned different books?

see
10,20,30,40
if u say search space should start at 10
then basically our search space starts from 10 and in case there comes a condition when a number less than a[n-1] comes as a true in the binary search

The task is to assign books in such a way that the maximum number of pages assigned to a student is minimum.

then since the i/p case are such that at most if there are n books then there are n children
so no all books could be read then

and also if u urself see in the code by updating the value of start = 0
then u`ll get wrong answer
the search space is wrong in that case

“The task is to assign books in such a way that the maximum number of pages assigned to a student is minimum.”

solution expected: max no of pages assigned to a student
task: to minimize the expected solution

eg. we have 4 books with 10,20,50,60 pages and have m=3.
possible solutions:

  1. {10+20, 50,60}, ans = 60
    2,{10+50,20,60} , ans = 60
  2. {10,20,50+60}, ans = 110(max no of pages a student get = 110)
    …so on
    final ans = in best case(min of all possible solutions), how many max pages a student will get = 60

eg2. 10,20,30,90 and m=2
possible solutions:

  1. {10+20,30+90}, ans = 120
    2.{10+20+30,90}, ans = 90
  2. {10+30,90+20}, ans = 110…so on
    final ans = min of all possible solutions = 90

you can see that the final answer can never be less than the largest book. since atleast some student will get that book and then the solution can never be less than that.

thanks
rate and resolve if satisfied.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.