link to my code : https://ide.codingblocks.com/s/228945
Getting wrong answer . please help
your is_possible code logic is not correct
correct code is
bool is_possible(int rank[], int chef, int p, int mid){
int no_of_parata=0;
for(int i=0;i<chef;i++){
/// for ith chef
int r=rank[i];
int time=0;
while(true){
time+=r;
if(time<=mid){
no_of_parata++;
}
else break;
r=r+rank[i];
}
}
if(no_of_parata>=p)return true;
else return false;
}
i didn’t understand your logic totally . can you please explain it ?
all chef will make paratas
so we iterate over all chefs one by one int first loop
now we said make parata you have time=mid
after making parata time will increase by (r as mention in question)
now we check if parata is made within time then increase parata count otherwise break
and now next chef make parata
in this way at end we are able to find how many paratas can be made in time=mid
now if this count is >=p then we return true else false;
every time we increase r with rank[i] because
for making first parata time require r(rank[i])
for first parata time require r(2rank[i])
for first parata time require r(3rank[i])