I have read the problem 4 times but I still not able to understand how we are getting this output.
Please explain this question and how
OUTPUT is 50
for
INPUT
2
2
5
1 10
Painter Problem Not able to understand
You have to solve this problem using binary search algorithm. Here you have to take two values,
long long int lower=maximum(ar,N);
long long int upper=sum_of_array(ar,N);
Now the search space will be from the lower to upper value, similar like a binary search, you will calculate the no of painters for every mid value calculated, and then you will check that
if(painters<=K)
{
ans=mid;
upper=mid-1;
}
else
{
lower=mid+1;
}
Try dry run this code so as to get required ans.