https://codeforces.com/contest/1406/problem/B
思路:直接正反兩個排序,列舉正排序中選0~5個,反排序中選5-i個,列舉取最大就好了,
注意:longlong和最小值開大,-0x3f3f3f3f不夠,
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+100;
typedef long long LL;
LL a[maxn],b[maxn];
bool cmp(LL a,LL b)
{
return a>b;
}
int main(void)
{
cin.tie(0);std::ios::sync_with_stdio(false);
LL t;cin>>t;
while(t--){
LL n;cin>>n;
for(LL i=0;i<=n+10;i++) a[i]=b[i]=0;
for(LL i=1;i<=n;i++) {
cin>>a[i];b[i]=a[i];
}
sort(a+1,a+1+n);//小到大
sort(b+1,b+1+n,cmp);//大到小
LL ans=-1e18;
for(LL i=0;i<=5;i++){//拿0,1,2,3,4,5個
LL j=5-i;LL sum=1;
for(LL k=1;k<=i;k++){
sum*=a[k];
}
for(LL k=1;k<=j;k++){
sum*=b[k];
}
ans=max(ans,sum);
}
cout<<ans<<endl;
}
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/41773.html
標籤:其他
上一篇:iOS 性能優化(二)安裝包瘦身
