0 and 1 test cases are giving wrong answer
Painter problem
#include
#include
#include
#include<stdio.h>
using namespace std;
bool check(long long int maxt,long long int x[],long long int n,long long int p,long long int t)
{
long long int i,cl,sum=0,a;
int f=0;
cl=p;
for(i=0;i<n;)
{
if(cl==0)
{
f=0;
break;
}
else
{ sum+=x[i]*t;
if(sum>maxt)
{
sum=0;
cl–;
}
else
{
i++;
}
}
}
if(i==n)
{
return true;
}
if(f==1)
{
return true;
}
else
{
return false;
}
}
int main() {
long long int n,p,t,x[100000],i,j,k,mid,l,h=0,ans;
cin>>n>>p>>t;
for(i=0;i<n;i++)
cin>>x[i];
sort(x,x+n);
for(i=0;i<n;i++)
h+=x[i]*t;
l=x[n-1]*t;
while(l<=h)
{
mid=(l+h)/2;
if(check(mid,x,n,p,t))
{
ans=mid;
h=mid-1;
}
else
{
l=mid+1;
}
}
cout<<ans%10000003;
return 0;
}
Pls add some comments in your bool check function as I m not able to understand your code… Wht exactly you are doing…
Pls add comments in the code ide only…