I am not getting correct solution

#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

hey @ranahiten8 please share your code using ide.codingblocks.com as it’s not readable here.
If you don’t know how to share it using ide.codingblocks.com you can also ask me that.

Hey there are lots of mistake in your code,

e= (2*arr[0]+(p-1)*arr[0])*p/2;
also while loop in the cook function is also not correct

try to take reference from this code, and apply it in yours.

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.