this is my code for the question , i want to know why i am getting tle.`#include
include
include
using namespace std;
int main() {
int t;
cin>>t;
while(t–){
int m,n;
cin>>m;
cin>>n;
if(m<4 || n<4 || m+n<11){
cout<<-1<<endl;
continue;
}
vector bat,bow;
for(int i=0;i<m;i++){
int x;
cin>>x;
bat.push_back(x);
}
for(int i=0;i<n;i++){
int x;
cin>>x;
bow.push_back(x);
}
sort(bow.begin(),bow.end());
sort(bat.begin(),bat.end());
long long ans=0;
int cnt=0;
for(int i=1 ; i<=4 ; i++)
{
ans+=bat[m-i];
ans+=bow[n-i];
}
cout<<"first four"<<ans<<endl;
int i=m-5 , j=n-5 , c=0;
while(i>=0 && j>=0 && c<3)
{
if(bat[i]>=bow[j])
{
ans+=bat[i];
i--;
}
else
{
ans+=bow[j];
j--;
}
c++;
}
// cout<<"c is "<<c<<endl;
if(c<3)
{
if(i<0)
{
while(j>=0 && c<3)
{
ans+=bow[j];
j--;
c++;
}
}
else if(j<0)
{
while(i>=0 && c<3)
{
ans+=bat[i];
i--;
c++;
}
}
else
{
break;
}
}
if(c<3)
{
cout<<-1<<endl;
continue;
}
cout<<ans<<endl;
}
return 0;
}`