Description
Given a set of n integers: A={a1, a2,..., an}, we define a function d(A) as below:
d(A)=sum{a[s1]~a[t1]}+sum{a[s2]~a[t2]}
The rule is 1<=s1<=t1<s2<=t2<=n.
Your task is to calculate d(A).
Input
The input consists of T(<=30) test cases. The number of test cases (T) is given in the first line of the input.
Each test case contains two lines. The first line is an integer n(2<=n<=50000). The second line contains n integers: a1, a2, ..., an. (|ai| <= 10000).There is an empty line after each case.
Output
Print exactly one line for each test case. The line should contain the integer d(A).
Sample Input
1
10
1 -1 2 2 3 -3 4 -4 5 -5
Sample Output
13
Hint
In the sample, we choose {2,2,3,-3,4} and {5}, then we can get the answer.
Huge input,scanf is recommended
AC代码:
相关推荐
poj2479代码 Maximum sum 对于这道题,我的思路是先从左到右,计算并存储每个节点
Finding Maximum Contiguous Subsequence Sum using divide-and-conquer approach
该论文为立体匹配算法,为计算机视觉算法,可实现位代码
A wind-generator (WG) maximum-power-pointtracking (MPPT) system is presented, consisting of a highefficiency buck-type dc/dc converter and a microcontroller-based control unit running the MPPT ...
关于“最大熵模型”的论文。大家有需要,可以的、下载来研究
Exact maximum a posteriori estimation for binary images 图像处理 重要论文
最大子数组总和maximum subarray sum使用Java语言中的所有复杂度来计算子数组的最大和。 1.O(n ^ 3) 2.O(n ^ 2) 3.O(n)
基于重要性采样的贝叶斯DOA估计,谢达,黄建国,本文为减小贝叶斯DOA估计方法的计算量,将重要性采样与贝叶斯方法相结合,提出了基于重要性采样的贝叶斯最大后验DOA估计方法,并给
CVPR_2019_Chu_Spot_and_Learn_A_Maximum-Entropy_Patch_Sampler_for_Few-Shot_Image PPT讲解
Maximum reward reinforcement learning: A non-cumulative reward criterion.pdf
CVPR_2019_Chu_Spot_and_Learn_A_Maximum-Entropy_Patch_Sampler_for_Few-Shot_Image 讲稿(配合PPT)
MLPnP_matlab-MLPnP - A maximum likelihood solution to the Perspective-N-Point problem.zip
MUSIC and maximum likelihood techniques on two-dimensional DOA estimation with uniform circular array
利用吉布斯采样和粒子滤波方法进行贝叶斯最大后验概率方位估计,田力伟,黄建国,贝叶斯最大后验概率方位估计方法(Bayesian maximum a posterior DOA estimator)性能优良,而且可以解相干源,尤其是在低信噪比条件...
between the maximum and present values of a stock or other security along with the time of occurrence of the maximum. At least for the usual model using a Wiener process with drift for the log of the ...
In this thesis, we introduce the principle of maximum causal entropy, a general technique for applying information theory to decision-theoretic, game-theoretic, and control settings where relevant ...
关于Maximum-Power-Point-Tracking,的文献
Maximum sub sequence sum
这篇文章是 opennlp 中最大熵模型实现的参考文档,对最大熵模型从原理、示例到实现都讲得非常清晰,配合代码学习受益匪浅。