please tell mistakes so that i can rectify that
Only two test cases are passing
the only problem is start point of your binary search.
s = 1;
it should be s = (max element in array)*t;
as the answer will never be less than (max element in array)*t.
why?
explanation:
“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:
{10+20, 50,60}, ans = 60
2,{10+50,20,60} , ans = 60
{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:
{10+20,30+90}, ans = 120
2.{10+20+30,90}, ans = 90
{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.
updated code: https://ide.codingblocks.com/s/214428
thanks
please rate and resolve if satisfied.