Here is a simple and easy solution with using vector pair and hashing. Its execution time is 0.01s.
#include <bits/stdc++.h>
using namespace std;
int main() {
//code
int t;
cin>>t;
while(t--)
{
int n,x,maximum=0;
cin>>n;
vector< pair<int,int> >mp;
vector<int> v;
for(int i=0;i<n;++i)
{
cin>>x;
v.push_back(x);
}
for(int i=0;i<n;++i)
{
cin>>x;
if(x>maximum)
maximum=x;
mp.push_back(make_pair(v[i],x));
}
sort(mp.begin(),mp.end());
int ar[maximum+1]={0};
for(int i=0;i<n;++i)
{
ar[mp[i].first]+=1;
ar[mp[i].second+1]-=1;
}
int mx=0,tim=0,sum=0;
for(int i=mp[0].first;i<=maximum;++i)
{
sum+=ar[i];
if(mx<sum)
{
mx=sum;
tim=i;
}
}
cout<<mx<<" "<<tim<<endl;
}
return 0;
}