Review needed of the following solution to the PRATA problem

#include
#include
#include<stdlib.h>
#include
using namespace std;

bool isPossible(int ranks [],int p,int cooks,int mid)
{
int count1=0,i;

for(int i=0;i<cooks;i++)
{
int j=1;
int sum=0;
while(sum<=mid)
{
sum=sum+j*ranks[i];
count1++;
j++;
}
count1–;
}
if(count1>=p)
{
return true;
}
else
return false;
}

int findMin(int ranks[],int p,int cooks)
{
int s=0,ans=0;
int e=INT_MAX;

while(s<=e)
{
int mid=(s+e)/2;

   if(isPossible(ranks,p,cooks,mid))
   {
       ans=mid;
       e=mid-1;
   }
  else
    s=mid+1;

}
return ans;

}

int main()
{
int t,p,cooks;
cin>>t;
cin>>p;
cin>>cooks;

int ranks[10];

for(int i=0;i<cooks;i++)
{
cin>>ranks[i];
}

cout<<findMin(ranks,p,cooks)<<endl;

}

please share the code on cb ide. its difficult to debug otherwise

You havent taken the i/p correctly

int main()
{
    int t, p, cooks;
    cin >> t;
    while(t--){
        cin>> p >> cooks;
        int ranks[10];
        for (int i = 0; i < cooks; i++)
        {
            cin >> ranks[i];
        }
        cout << findMin(ranks, p, cooks) << endl;
    }
}

the int main code looks like this
t test cases, p paranthas n cooks

1 Like

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.