Untitled
user_5668965
c_cpp
a year ago
800 B
17
Indexable
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
void solve()
{
ll n;
cin>>n;
ll a[n],b[n];
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++)cin>>b[i];
sort(a,a+n);
sort(b,b+n);
ll l=0,r=n,ans=0;
while(l<=r)
{
ll mid=(l+r)/2;
// n-mid-1
bool cd=1;
for(int i=n-mid;i<n;i++)
{
if(b[i]<a[i-n+mid])cd=0;
}
if(cd){
l=mid+1;
ans=mid;
}
else{
r=mid-1;
}
}
ans=n-ans;
cout<<(n*(n+1))/2-(ans*(ans+1))/2<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll t=1;
cin>>t;
while(t--)solve();
}Editor is loading...
Leave a Comment