标签:traints positive out aced nsis number pac air case
Given an array of n elements.Find the maximum sum when the array elements will be arranged in such way. Multiply the elements of each pair and add to get maximum Sum. Sum could be larger so take mod with 10^9+7.
Example1: Input: n=7 -1,9,4,5,-4,-7,0 Output: 77 So to get the maximum sum,the arrangement will be {-7,-4},{-1,0},{9,5} and {4}.So the answer is (-7*(-4))+((-1)*0)+(9*5)+(4) ={77}. Example2: Input: n=3 -1,0,1 Output: 1 So to get the maximum sum,the arrangement will be {-1,0} and {1}.So the answer is ((-1)*0)+(1)={1}.
Input:
The first line consists of an integer T i.e number of test cases. The first line of each test case consists of an integer n.The next line consists of n spaced integers(positive or negative).
Output:
Print the maximum sum % 10^9+7.
Constraints:
1<=T<=100
1<=n,a[i]<=10000
Example:
Input:
2
3
8 7 9
6
-1 9 4 5 -4 7
Output:
79
87
下面是我的代码实现:
标签:traints positive out aced nsis number pac air case
原文地址:http://www.cnblogs.com/wongyi/p/7676839.html