School of Geometry - SNUG_FIT CodeCHEF Easy Question

Hello Everyone , today we will be discussing a very easy beginner level problem of Code CHEF

Here is the link to the PROBLEM

So , the problem is pretty straightforward.

So , for the solution , we just need simple geometry and we get to know that the diameter of the circle will be the smaller of the two sides of the rectangle .

So , with the largest A , get the largest B and hence find the smaller of the two and add it to the sum .
You will have the answer in the end .

Please look at the C++ code and ask your doubts in the comments section .

#include <iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
    int t;
    int n;
    long s;
    scanf("%d",&t);
    while(t--)
    {   long i=0;
        s=0;
        scanf("%d",&n);
        long arr1[n];
        long arr2[n];
        while(i!=n)
        {
            arr1[i]=0;
            arr2[i]=0;
            i++;
        }
        i=0;
        while(i!=n)
        {
            scanf("%d",&arr1[i]);
                i++;
        }
         i=0;
        while(i!=n)
        {
            scanf("%d",&arr2[i]);
         
            i++;
        }
        sort(arr1,arr1+n);
        sort(arr2,arr2+n);
        i=0;
        while(i!=n)
        {
            if(arr1[i]<arr2[i])
            {
                s=s+arr1[i];
            }
            else
            {
                s=s+arr2[i];
            }
           
            i++;
        }
        cout<<s<<endl;
    }
return 0;
}



Comments

Popular Posts