Not getting right output

#include
#include<math.h>
#include

using namespace std;

bool cook(int p,int n,int r[],int mid)
{
int c,sum=0,i;
for(i=0;i<n;i++)
{
int c=sqrt((2*mid)/r[i]);
sum=sum+c;
}

return sum>=p;

}

int main()
{
long long int p,n,first,last,mid,i,ans;
cin>>p>>n;
int r[n];

for(i=0;i<n;i++)
cin>>r[i];

first=1;
last=100;

while(first<=last)
{
    mid=(first+last)/2;
	if(cook(p,n,r,mid))
    {
        ans=mid;
        last=mid-1;
    }

    else 
    first=mid+1;
}

cout<<ans;

return 0;

}

The value of your range is wrong. Take a bigger value of r.

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.