Problem: Contest Page | CodeChef
DIFFICULTY:
EASY.
PROBLEM:
Chef has an array of N natural numbers. Cheffina challenges the chef to choose the two numbers from the array and following the condition as the area of the rectangle formed from the two numbers is maximum. Cheffina also asks the chef to choose two numbers different from the previous two to form the rectangle with a minimum area.
Program:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
long long arr[n];
for(int i=0;i<n;i++)cin>>arr[i];
sort(arr,arr+n);
long long mx=arr[n-1]*arr[n-2];
long long mn=arr[0]*arr[1];
cout<<mx<<" "<<mn<<endl;
}
}