标签:
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
const int oo = 1e9;
const int N = 5*1e6+8;
const int M = 6000;
typedef long long LL;
int ac[N], n;
LL ans;
struct da
{
int num, id;
} as[N];
int cmp1(da a, da b)
{
return a.num < b.num;
}
int cmp2(da a, da b)
{
return abs(a.num) < abs(b.num);
}
int main()
{
int i, T, a, b, A1, A2, B1, B2, ma, mb, xx=1;
LL sum;
scanf("%d", &T);
while(T--)
{
scanf("%d %d %d", &n, &a, &b);
for(i = 0; i < n; i++)
{
scanf("%d", &as[i].num);
as[i].id = i;
}
A1 = A2 = B1 = B2 = 0;
sort(as, as+n, cmp2);
if(a >= 0) A1 = as[n-1].num, A2 = as[n-1].id, ma = as[n-2].num;
else A1 = as[0].num, A2 = as[0].id, ma = as[1].num;
sort(as, as+n, cmp1);
if(b >= 0) B1 = as[n-1].num, B2 = as[n-1].id, mb = as[n-2].num;
else B1 = as[0].num, B2 = as[0].id, mb = as[1].num;
if(A2 != B2)
{
ans = (LL)a*A1*A1;
ans += (LL)b*B1;
}
else
{
ans = (LL)a*A1*A1;
ans += (LL)b*mb;
sum = (LL)a*ma*ma;
sum += (LL)b*B1;
ans = max(ans, sum);
}
printf("Case #%d: %I64d\n", xx++, ans);
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/PersistFaith/p/4821904.html