What's wrong in my approach?
for(int i=0;i<n;i++){
int p=0;
while(p+a[j]<=mid&&j<=n-1){
j++;
p=p+a[j];
if(p+a[j]>mid){
p = 0 ;
cnt++;}
}
}
yeh code ka logic galat h
use this
bool isValidConfig(ll arr[], ll n, ll m, ll ans)
{
int students = 1;
ll currentpages = 0;
for (int i = 0; i < n; i++)
{
if (currentpages + arr[i] > ans)
{
currentpages = arr[i];
students++;
if (students > m)
{
return false;
}
}
else
{
currentpages += arr[i];
}
}
return true;
}
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.
do let me know what is wrong in my code
start point is wrong
refer to this code