题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=5461
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1e7;
struct hh
{
long long x;
long long y;
}maxa[maxn],maxb[maxn];
bool cmp(hh a, hh b)
{
return a.y < b.y;
}
int main()
{
int t;
scanf("%d", &t);
long long n, a, b;
int Case = 1;
while (t--)
{
scanf("%lld%lld%lld", &n, &a, &b);
long long x;
for (int i = 0; i < n; i++)
{
scanf("%lld", &x);
maxa[i].x = i + 1;
maxa[i].y = a*x*x;
maxb[i].x = i + 1;
maxb[i].y = b*x;
}
sort(maxa, maxa + n, cmp);
sort(maxb, maxb + n, cmp);
if (maxa[n - 1].x != maxb[n - 1].x)
{
printf("Case #%d: %lld\n", Case++, maxa[n - 1].y + maxb[n - 1].y);
continue;
}
long long sum1, sum2;
sum1 = maxa[n - 1].y + maxb[n - 2].y;
sum2 = maxb[n - 2].y + maxb[n - 1].y;
if(sum1>sum2)
printf("Case #%d: %lld\n", Case++, sum1);
else
printf("Case #%d: %lld\n", Case++, sum2);
}
}