# Help me in solving ARRHALVES problem

### 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

@akhon
I think two pointer approach would work fine in this problem.
like just making sure that first half contains all element less than or equals N and second half contain all element >N . if we will sort the array it will take more operations thus two pointer will find the element >N in the first half and <=N in the second half and then apply operation on them.