y=axixi+bj (i!=j),求y最大值
求a部分最大值和次大值,b同理。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
#define LL long long
const int maxn = 5e6 + 10;
LL x[maxn];
int main()
{
int t, cas = 0;
scanf("%d", &t);
while (t--)
{
LL n, a, b;
LL max1, max2, max3, max4;
max1 = -1e15; max2 = -1e15, max3 = -1e15, max4 = -1e15;;
int flaga,flagb;
cin >> n >> a >> b;
for (int i = 1; i <= n; i++)
{
scanf("%lld", &x[i]);
if (a * x[i] * x[i] > max1) max1 = a * x[i] * x[i], flaga = i;
if (b * x[i] > max2) max2 = b * x[i], flagb = i;
}
for (int i = 1; i <= n; i++)
{
if (a * x[i] * x[i] > max3 && i != flaga) max3 = a * x[i] * x[i];
if (b * x[i] > max4 && i != flagb) max4 = b * x[i];
}
LL ans;
if (flaga != flagb)ans = max1 + max2;
else ans = max(max1 + max4, max2 + max3);
printf("Case #%d: %lld\n", ++cas, ans);
}
return 0;
}