思路:直接分成两部分考虑,排个序就可以了
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn = 5*1e6+7;
LL a[maxn];
struct Node
{
LL w;
int id;
}a1[maxn],b1[maxn];
bool cmp(Node a,Node b){return a.w>b.w;}
int main()
{
int T,cas=1;
scanf("%d",&T);
while(T--)
{
int n;
LL aa,bb;
scanf("%d%lld%lld",&n,&aa,&bb);
for(int i = 1;i<=n;i++)
{
scanf("%lld",&a[i]);
a1[i].w = aa*a[i]*a[i];
a1[i].id = i;
b1[i].w = bb*a[i];
b1[i].id = i;
}
sort(a1+1,a1+1+n,cmp);
sort(b1+1,b1+1+n,cmp);
if(a1[1].id!=b1[1].id)
{
printf("Case #%d: %lld\n",cas++,a1[1].w+b1[1].w);
continue;
}
else
printf("Case #%d: %lld\n",cas++,max(a1[1].w+b1[2].w,a1[2].w+b1[1].w));
}
}