Bridge problem getting wrong answer

import java.util.Scanner;

public class Main {
public static void main(String agrsp[]){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int f=0;f<t;f++){
int n=sc.nextInt();
int a[]=new int[n];
int b[]=new int[n];
int dp[]=new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
for(int i=0;i<n;i++){
b[i]=sc.nextInt();
}
int mm=0;
dp[0]=1;

        for(int i=0;i<n;i++){
            int max=0;
            for(int j=0;j<i;j++){
                if( (a[i]<a[j] && b[i]<=b[j]) || (a[i]>a[j] && b[i]>=b[j]) || (a[i]<=a[j] && b[i]<b[j]) || (a[i]>=a[j] && b[i]>b[j]))
                   dp[i]= Math.max(dp[i],dp[j]+1);

            }
            if(dp[i]==0)
                dp[i]=1;
            //System.out.print(dp[i]+" ");
        }
        for(int i=0;i<n;i++){
            if(dp[i]>mm)
                mm=dp[i];
        }
        System.out.println(mm);
        //System.out.println(mm);


    }
}

}

Hey @Anubhav44044
Please provide your code on Coding blocks ide.

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.