Murthal parantha

#include
#include
using namespace std;

int tym(int rank,int par){ return (par*(par+1)/2)*rank;}

bool mintym(int par,int cooks,int ranks[],int m){
int mintime,j=0,tm=0,i=1;
while(par)
{
if(tym(ranks[j],i)<m) { i++; par–;}
else { j++; if(j==cooks) return false; i=1; tm=0; }
}
return true;
}

int calc(int par,int cooks,int ranks[]){
int s=tym(ranks[0],1),e=tym(ranks[cooks-1],par),m,ans;
while(s<=e){
m=(s+e)/2;
if(mintym(par,cooks,ranks,m)) { ans=m; e=m-1; }
else s=m+1;
}
return ans-1;
}

int main() {
int par,cooks; cin>>par>>cooks;
int ranks[cooks];
for(int i=0;i<cooks;i++) cin>>ranks[i];
sort(ranks,ranks+cooks);
cout<<calc(par,cooks,ranks);
}

why is it incorrect…one test case is giving wrong answer

also…in this code…ans is coming wrong…like for 12…it is showing 13…and for 18, it is showing 19…answer it shows is always greater by 1 than the original answer…that is why i have returned ‘ans-1’ in the code

Hey can you provide properly indented and documented code. (i.e. with comments)


I have found your mistake. In function bool mintym( , , , ) > In while loop > The if condition is wrong.

if(tym(ranks[j],i)<=m) { i++; par–;}

The sign must be less than equal to and after correcting this mistake. You can return ans instead of ans - 1 for correct answer.

return ans;

thank u very much sir…

1 Like