Painter Problem

#include
#include<bits/stdc++.h>

using namespace std;
#define ll long long int
bool isValidConf(ll arr[],ll n,ll m,ll k,ll answer)
{
int count=1;
ll curlength=0;
for (int i = 0; i < n; i++)
{
if (curlength + arr[i] > answer)
{
curlength = arr[i];
count++;

        if (count > m)
        {
            return false;
        }
    }
    else
    {
        curlength += arr[i];
    }
}
return true;

}

ll painterproblem(ll arr[],ll n,ll m,ll k)
{
ll s=0;
ll end=0;
for(int i=0;i<n;i++)
{
end+=arr[i];
s=max(s,arr[i]);
}

int ans=0;

while(s<=end)
{
int mid=(s+end)/2;

   if(isValidConf(arr,n,m,k,mid))
   {
	   ans=mid;
	   s=mid+1;
   }

   else
   {
	   end=mid-1;
   }

}

return ans;
}

int main() {

ll n,m,k;

ll arr[n];

for(int i=0;i<n;i++)
{
	cin>>arr[i];
}

cout<<painterproblem(arr,n,m,k);

return 0;

}

Please send your code on CB IDE. And what exactly is the issue with the code.

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.