Break the Server Students height IQs

I think I am failing test cases in this problem :

Where am I going wrong ?
.
.
.
My code :

https://www.codechef.com/viewsolution/42951656

lsp[i] = max(lsp[j]+1, lsp[j]);
This line

thanks for your reply, can you just brief it out?

Its should be
lsp[i] = max(lsp[j]+1, lsp[i]);
right? Just a typo
cuz max(x+1,x) is always x+1 :stuck_out_tongue:

1 Like

oh god ! ya :rofl: you just saved me thanks mate!

1 Like

Could You Review my code also and tell whats wrong for same Question
It will be really helpful
Thanks in advance

if ( h[i] > x and iq[i] < y ) {
return 1 + rt(h,iq,i+1,n,h[i],iq[i] ) ;
}

Should be

if ( h[i] > x and iq[i] < y ) {
return max( rt(h,iq,i+1,n,x,y ) ,1 + rt(h,iq,i+1,n,h[i],iq[i] )) ;
}

But now it might go exponential so maybe memoize it.

3 Likes

Thanks Bro I got the case you explained
But still after doing correction it is giving me the wrong ans .
Here’s the link

for ( int i = 0 ; i < n ; i++ ) {
int h = v[i] ;
int iq = t[i] ;
curr = 1+rt(v,t,i+1,n,h,iq) ;
max_sub = max ( curr , max_sub ) ;
}

should be

for ( int i = 0 ; i + 1 < n ; i++ ) {
int h = v[i] ;
int iq = t[i] ;
curr = 1+rt(v,t,i+1,n,h,iq) ;
max_sub = max ( curr , max_sub ) ;
}

1 Like

Can you please review my code…Thank you in advance, sir.
https://www.codechef.com/viewsolution/43034070