code not working please help
Https://ide.codingblocks.com/s/142570 code not working please help
Kartik, your code is not producing correct output in sample test cases, I would recommend you to go through the online video lecture for the following problem as ,
that i know lol that its not giving me the desired output
i am applying the same approach but could not track the error
Kartik, in the code, you have to take
int start=0;
int end = sum;
while(start<=end)
{
long long int mid=(start+end)/2;
if(isValid(ar,n,m,mid))
{
end=mid-1;
finalans=mid;
}
else
{
start=mid+1;
}
}
and in the isValid function , include these conditions, as
if(ar[i]>ans)
{
return false;
}
if(currentpages+ar[i]>ans)
{
currentpages=ar[i];
student++;
if(student>m)
{
return false;
}
}
else
{
currentpages=currentpages+ar[i];
}