SNUG_FIT-Editorial

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;}
1 Like

I didn’t do anything different than this still I’m getting a TLE in my code, my code is ditto same, I just used printf() and scanf() instead of cin and cout

and please would you tell me how to access #include<bits/stdc++.h>
it’s showing me an error

@tanujyadav007 would you please tell me what’s wrong here?

#include<bits/stdc++.h>

using namespace std;

int main()
{
int tc, n;
// scanf("%d", &tc);
cin>>tc;
while (tc–)
{
long long int sum = 0;
// scanf("%ld", &n);
cin>>n;
long int len[n], wid[n];
for(int i = 0; i < n; i++)
// scanf("%ld", &len[i]);
cin>>len[i];
for(int i = 0; i < n; i++)
// scanf("%ld", &wid[i]);
cin>>wid[i];
sort(len, len + n);
sort(wid, wid + n);
for ( int i = 0; i < n; i++)
{
sum += min(len[i], wid[i]);
}
// printf("%lld", sum);
cout<<sum<<endl;
}

return 0;
}

@omkarg1417 use tc-- instead of tc- :slight_smile:

1 Like

where bro

In while loop . here i am talking about @omkarg1417 's code

ok bro