i am not able to find the mistake in my code. please someone help me out.
https://ide.codingblocks.com/s/72948
Aggressive cows-mistake in my code
@Mrinali_Mangal hey mrinali
there is some error in your code
in line 7 do currentpage=0; instead of doing like that currentpage=books[0];
reason for doing this you are assigning the contain of book array at position 0 to current page but initally current page should be zero
in line 11 the condition is like books[i]+currentpage> mid
and in line 21
else{
currentpage+=books[i];
}
in the accom function
you are again assigning the contain of the array how you will calculate index of mid with the contain of the array
you have to work here on the index of the array
so update here accom function like
int total_pages=0;
int s=0;
int e=0;
for(int i=0;i<n;i++){
total_pages+=books[i];
s=max(s,books[i]);
}
e=total_pages;
int finalans=s;
in line no 32
int mid =(s+e)/2;
in line no 38 e=mid-1;
in line no 41 s=mid+1;