In this problem we have to inscribed a circle in a rectangle that is formed from two sequences that is given to us.
So to maximize the sum of diameter of circles we have to take one side from each of both sequences but we choose those two sides that are relatively equal to each other that means difference between then is less.
So, to do this we sort both the sequences and take element in ascending order from both the array.
Whenever a circle is inscribed in a rectangle then the smallest side of rectangle is equal to the diameter of the circle.
The code for this particular problem is:
/*school of geometry*/
/****killing like kamikaze****/
/*tanuj yadav*/
/**********************/
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,n;
cin>>t;
for(int i=0;i<t;i++)
{
long long int sum=0;
cin>>n;
long int a[n],b[n];
for(int j=0;j<n;j++)
{
cin>>a[j];
}
for(int j=0;j<n;j++)
{
cin>>b[j];
}
sort(a,a+n);
sort(b,b+n);
for(int j=0;j<n;j++)
{
sum += min(a[j],b[j]);
}
cout<<sum<<endl;
}
return 0;}