### My issue

so i have TLE error for last 2 case which is understandable .If u r an expert what advice will u give me here…am i overcomplicating the problem?

### My code

```
#include <bits/stdc++.h>
using namespace std;
int main() {int t,n;
cin>>t;
while(t--){int k=0,s=0;
cin>>n;
n=2*n;
vector <int> a(n/2);
vector <int> b(n/2);
vector <int> c(n/2);
vector <int> d(n/2);
for(int i=0;i<n;i++){
if(i<n/2){
cin>>a[i];
c[i]=a[i];
}
else{
cin>>b[i-n/2];
d[i-n/2]=b[i-n/2];
}
}
sort(c.begin(),c.end());
sort(d.begin(),d.end());
for(int i=0;i<n/2;i++){
if(c[n/2 -i-1]>d[i]){
k++;
}
else{
break;
}
}
for(int i=0;i<n/2;i++){
for(int j=0;j<k;j++){
if(a[i] == c[n/2 - j-1]){
s+=n/2 -i -1;
break;
}
}
}
for(int i=0;i<n/2;i++){
for(int j=0;j<k;j++){
if(b[i] == d[j]){
s+=i+1 ;
break;
}
}
}
cout<<s<<endl;
}
return 0;
}
```

Problem Link: ARRHALVES Problem - CodeChef