Please help me with the logic of painters problem!

code:

i am unable to think the logic part.

I have edited your code a little bit, I have added some comments also, Pls refer to the code as :

Also, You are supposed to take a bool function, bool karPaye, Apply the logic as given below in isPossible function as :

bool isPossible(long long int arr[], long long int k, long long int mid, long long int n)
{
long long int painters=1;
long long int time_taken=0;
for(int i=0;i<n;i++)
{
if(time_taken+arr[i]>mid)
{
painters++;
time_taken=arr[i];
if(painters>k)
{
return false;
}
}
else
{
time_taken=time_taken+arr[i];
}
}
return true;
}

my code is failing 1,3,and 5 th testcases.

Ok…I will try to see it

I have edited your code…Try to submit now…