题意:
有一个数列 t ,以及两个整数a,b,求 的最大值。
只要找出t中最小值,次小值,最大值,次大值,绝对值最小值,然后全排列就能得到答案,注意不能取同一个
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
typedef long long int LL;
const LL INF = 1e18 + 1e17;
LL T, n, a, b, v[10], x[5000000+50], ans, cas, temp;
int main()
{
scanf("%lld",&T);
while(T--){
for(int i=1;i<=5;i++) v[i] = INF;
scanf("%lld%lld%lld",&n,&a,&b);
for(int i=1;i<=n;i++) scanf("%lld",&x[i]);
sort(x+1, x+1+n);
// v1 ~ v5 分别为最小值,次小值,最大值,次大值,绝对值最小值
v[1] = x[1]; v[2] = x[2];
if(n>=3) v[3] = x[n];
if(n>=4) v[4] = x[n-1];
for(int i=3;i<=n-2;i++) if(abs(x[i]) < abs(v[5])) v[5] = x[i];
ans = -INF;
do{
if(v[2] == INF || v[1] == INF) continue;
ans = max(ans, a*v[1]*v[1]+b*v[2]);
}while(next_permutation(v+1,v+6));
printf("Case #%lld: %lld\n", ++cas, ans);
}
return 0;
}