點選打開連結
time limit: 1500/1000 ms (java/others) memory limit: 65535/32768 k (java/others)
total submission(s): 474 accepted submission(s): 213
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 nintegers 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
source
2015 acm/icpc asia regional shenyang online
題目大意:有t組資料,然後第一行有三個數n, a, b;
接下來有n行arr[i],求a * arr[i] + b * arr[j] 的最大值(i != j)
解題思路:
分四種情況讨論,有點麻煩,但是卻管用,先對arr數組排一下序,
然後在對絕對值數組data排一下序,在判斷一下是不是絕對值數組的最值跟原先數組的最值一樣,
最後在确定是不是有多個最值就okl
上代碼: