Help me in solving TWOCARD problem

My issue

can it be done in linear time complexity

My code

#include <bits/stdc++.h>
using namespace std;
bool solve(vector<int> A,vector<int> B){
    vector<pair<int,int>> t;
    for(int l=0;l<A.size();l++){
        t.push_back({A[l],B[l]});
    }
    sort(t.begin(),t.end());
    int i=t.size()-1;
    while( i>=0 ){
        if( max(t[i].first,t[i].second) > max(t[i-1].first,t[i-1].second)) return true;
    }
    return false;
}
int main() {
    int T;
    cin>>T;
    for(int t=0;t<T;t++){
        int N;
        cin>>N;
        vector<int> A(N);
        vector<int> B(N);
        for(int i=0;i<N;i++){
            cin>>A[i];
        }
        for(int i=0;i<N;i++){
            cin>>B[i];
        }
        bool ans=solve(A,B);
        if( ans ) cout<<"Yes";
        else cout<<"No";
        cout<<endl;
    }
}

Problem Link: Two Cards Practice Coding Problem