#include
using namespace std;
bool cook(int p,int c,int r[],int mintime)
{
int pratacounter=0;
for(int i=0;i<c;i++)
{
int n=1;
int totaltime=0;
while(totaltime<=mintime)
{
totaltime+=n*r[i];
n++;
pratacounter++;
}
pratacounter–;
}
if(pratacounter>=p)
{
return true;
}
else
{
return false;
}
}
int main()
{
//no of prata cook and rank of cook array
int p,c,r[50];
cin>>p;
cin>>c;
//input values in increasing order of ranks so that sort algo na lagani pade is program me
for(int i=0;i<c;i++)
{
cin>>r[i];
}
//binary search algo
int s,e,mid;
s=0; //minimum time to make all prata assume
e=r[0]*p*(p+1)/2; //min time to make all prata by best cook alone
int ans=-1;
while(s<=e)
{
mid=s+e/2;
int cancook=cook(p,c,r,mid);
if(cancook)
{
ans=mid;
e=mid-1;
}
else
{
s=mid+1;
}
}
cout<<ans;
}
please check my code and tell the problem