Please help me with the isvalid func

cant able to uild logic for is valid func please help

This is basically a binary search problem, where you have to go about something like book allocation problem,
u define the min time = no_of_parantas and max time = INT_MAX
Then do binary search over the range , check if the current time that is mid of min_& max_ time can lead to a possible minimum solution,
`bool isPossible(vector &rnk, int minTime,int paranthas){
int n=rnk.size();

for(int i=0;i<n;i++){
int tm=0;
int ct=1;
while(tm+ctrnk[i]<=minTime and paranthas>0){
tm+=ct
rnk[i];
paranthas–;
ct++;
}
if(paranthas==0)return true;
}
return (paranthas==0);
}`

reduce the search interval in each pass, and there u get to the correct answer.

whats ct rnkin the code?

one test case not passing

ct is basically 1r 2r 3*r so ct+=1 is the time, rnk[] is basically the rank array

Could u share ur code
The entire code.

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.