Break The Server Students Heights and IQs

Below is Link of Question

And solution

It is Working on sample but giving wrong ans
plz tell which cases i’m missing or solution is not proper

Approach can be easily undestood from the code .

I can’t see the solution you submitted… The link is just pointing to the codechef ide

This question is just the same as the longest subsequences problem Longest Increasing Subsequence | DP-3 - GeeksforGeeks in the LIS function just you need to pass an extra array which is IQ array and in if condition just put an extra condition IQ[i]<IQ[j] and rest all is same.

@swil128
I Think I followed the same concept
Can You Review the code once
I have added it .

Sorry For Inconvinience
Now You can see the solution .

Here is the code:-

#include<bits/stdc++.h>
#define int long long int
#define nitro ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define pb push_back
using namespace std;

int lis( int arr[],int b[], int n )
{
int lis[n];

lis[0] = 1;    

/* Compute optimized LIS values in  
   bottom up manner */
for (int i = 1; i < n; i++ )  
{ 
    lis[i] = 1; 
    for (int j = 0; j < i; j++ )   
        if ( arr[i] > arr[j] && b[i] <b[j] && lis[i] < lis[j] + 1)  
            lis[i] = lis[j] + 1;  
} 

// Return maximum value in lis[] 
return *max_element(lis, lis+n); 

}

signed main()
{
nitro;
int t;
cin>>t;
while(t–){
int n;
cin>>n;
int a[n],b[n];
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n;i++)
cin>>b[i];
int ans=1ll;
if(n==1)
cout<<1<<’\n’;
else
{
ans=lis(a,b,n);
cout<<ans<<’\n’;
}
}
return 0;
}

1 Like

Thanks For This Bro .
But i need the Top Down approach .
Rec+Mem

same here

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

1 Like

Thanks . This is the thing which i was wanted .

1 Like

welcome