Codeforces 1406B. Maximum Product Solution
Solution in C++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,i,n,j;
cin>>t;
for(i=1; i<=t; i++)
{
cin>>n;
long long a[n+1];
for(j=0; j<n; j++)
{
cin>>a[j];
}
sort(a,a+n);
long long r1,r2,r3;
r1=a[n-1]*a[n-2]*a[n-3]*a[n-4]*a[n-5];
r2=max(r1,a[n-1]*a[0]*a[1]*a[2]*a[3]);
r3=max(r2,a[0]*a[1]*a[n-1]*a[n-2]*a[n-3]);
cout<<r3<<endl;
}
}
No comments