Largest Point
 Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
 Total Submission(s): 548    Accepted Submission(s): 234
 

Problem Description
 
Given the sequence A with n integers t1,t2,?,tn. Given the integral coefficients a and b. The fact that select two elements ti and tj of A and i≠j to maximize the value of at2i+btj, becomes the largest point.
 
 
 

Input
 
An positive integer T, indicating there are T test cases.
 For each test case, the first line contains three integers corresponding to n (2≤n≤5×106), a (0≤|a|≤106) and b (0≤|b|≤106). The second line contains n integers t1,t2,?,tn where 0≤|ti|≤106 for 1≤i≤n.
 
The sum of n for all cases would not be larger than 5×106.
 
 
 

Output
 
The output contains exactly T lines.
 For each test case, you should output the maximum value of at2i+btj.
 
 
 

Sample Input
 
2

3 2 1
1 2 3

5 -1 0
-3 -3 0 3 3
 
 

Sample Output
 
Case #1: 20
Case #2: 0

//要考虑s的最小绝对值与s的最大值相等或为同一个数时的情况。(在这块错了6次)

#include
#include
#include
#include
using namespace std;
#define INF 0x3f3f3f3f
int s[3000100];
int c[1000100];
int main()
{
	int t;
	int i,j,k,n,a,b;
	int cnt=1;
	long long int sum,mm;
	scanf("%d",&t);
	while(t--)
	{
		memset(c,0,sizeof(c));
		sum=0;
		scanf("%d%d%d",&n,&a,&b);
		for(i=1;i<=n;i++)
			scanf("%d",&s[i]);
		printf("Case #%d: ",cnt++);
		if(a>0)
		{
			mm=-INF;
			for(i=1;i<=n;i++)
			{
				if(abs(s[i])>mm)
				{
					k=i;
					mm=abs(s[i]);
				}
			}
			c[k]=1;
			sum+=a*mm*mm;
		}
		else
		{
			if(a<0)
			{
				mm=INF;
				for(i=1;i<=n;i++)
				{
					if(abs(s[i])0)
		{
			mm=-INF;
			for(i=1;i<=n;i++)
			{
				if(s[i]>mm&&!c[i])
				{
					mm=s[i];
				}
			}
			sum+=b*mm;
		}
		else
		{
			if(b<0)
			{
				mm=INF;
				for(i=1;i<=n;i++)
				{
					if(s[i]
#include
#include
#include
using namespace std;
int s[5000100];
int main()
{
	int t,cnt=1;
	int n,a,b,i,j;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d%d",&n,&a,&b);
		for(i=1;i<=n;i++)
			scanf("%d",&s[i]);	
		printf("Case #%d: ",cnt++);	
		if(a>=0&&b>=0)
		{
			sort(s+1,s+n+1);
			if(abs(s[1])>s[n])
				printf("%lld\n",a*s[1]*s[1]+b*s[n]);
			else
				printf("%lld\n",a*s[n]*s[n]+b*s[n-1]>a*s[n-1]*s[n-1]+b*s[n]?a*s[n]*s[n]+b*s[n-1]:a*s[n-1]*s[n-1]+b*s[n]);
		}
		else if(a>0&&b<0)
		{
			sort(s+1,s+n+1);
			if(abs(s[1])>s[n])
				printf("%lld\n",a*s[1]*s[1]+b*s[2]>a*s[n]*s[n]+b*s[1]?a*s[1]*s[1]+b*s[2]:a*s[n]*s[n]+b*s[1]);
			else
				printf("%lld\n",a*s[n]*s[n]+b*s[1]);
		}
		else if(a<0&&b>0)
		{
			sort(s+1,s+n+1);
			int mm=s[n];
			int nn=s[n-1];
			for(i=1;i<=n;i++)
				s[i]=abs(s[i]);
			sort(s+1,s+n+1);
			if(mm!=s[1])
				printf("%lld\n",a*s[1]*s[1]+b*mm);
			else
				printf("%lld\n",a*mm*mm+b*nn>a*s[2]*s[2]+b*mm?a*mm*mm+b*nn:a*s[2]*s[2]+b*mm);
		}
		else 
		{
			sort(s+1,s+n+1);
			int mm=s[1];
			int nn=s[2];
			for(i=1;i<=n;i++)
				s[i]=abs(s[i]);
			sort(s+1,s+n+1);
			if(mm!=s[1])
				printf("%lld\n",a*s[1]*s[1]+b*mm);
			else
				printf("%lld\n",a*mm*mm+b*nn>a*nn*nn+b*mm?a*mm*mm+b*nn:a*nn*nn+b*mm);
		}
	}
	return 0;
}