Please tell me where the error and how to rectify it asap

bool isPossible(int p,int cook[],int n,int mid){ int cnt = 0; for(int i=0;i<n;i++){ //for each cook count the pratas int c = 0; int time = mid; int perpratas = cook[i]; // time taken to cook each pratas by ith cook while(time > 0){ time = time - perpratas; if( time >= 0){ c += 1; perpratas += cook[i]; } } cnt += c; if(cnt >= p) return true; }

I didnt understood this function can you explain also i asked you to tell the error in my code.


so basically since we need to find the minimum time
in the ispossible function we iterate through the chef rank array and
checking how many paranthas can be cooked by the chef in that time( mid)
and it is given
if rank = 2
then 1 parantha in 2 min then next in 4 min then 6 minutes
so this computation is being done i n

 int perpratas = cook[i]; // time taken to cook each pratas by ith cook
        while(time > 0){
            time = time - perpratas;
            if( time >= 0){
                c += 1;
                perpratas  += cook[i];
            }
        }

perpratas ka the time taken to cook the parantha and vo har parantha banane ke sath increase ho raha h
by a factor = rank of chef ie == chef[i]

hence for each cook cal. total paranthas made
add it to total parantha
if it is greater than equal to required no of paranthas return true
else false

i suppose prataop function and also dont take array size as a[100] or some constant always make it
a[n]

yeah but sometimes when I take a[n] it won’t work for all the test cases and if I take a[10000] specified in the constraints then it will work.

I am not clear with this part when to take a[n] and when a[1000] by looking at the constraints.

always take a[n]
a[some constant ] is always risky

that’s what I am saying in many situations I have to take a[constant] to make it work for all the test cases a[n] won’t work for that case

yr aise nhi hota
like mene to kafi code kia h
never encountered this situation so i cant guide u over this

a[n] n means the maximum range that array vale can go up to

okay thanl you so much.

1 Like