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

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.