In Statistics, the median of an array of integers is a value which
divides array
into two equal parts: the higher half and the lower
half.
In the case when is odd, the median is
clearly defined: the middle value of the sorted version of
array . In the
case when is
even, the median is the average of the two middle values,
rounded down so that we always have an
integer median.
In this problem, your task is to compute median values as
integers are added into array one by one. Since this is
an incremental process, we call these “continuous medians”. To
simplify this problem, you just need to output the sum of the
medians of at
the end.
Input
The first line of input contains an integer , denoting the number of test cases
. Each
test case consists of two lines and the first line contains
just one integer
.
This is followed by
integers of array in the next line. Each
integer in is
non-negative and is not more than .
Note: For all input, there will be at
most
integers.
Output
For each test case, output the sum of the
continuous medians of in one line.
Explanation
In the first sample test case, and .
When you read the integer of array , you need to compute the
current continuous median of array , as shown in Table 1. Thus, is the answer for
this first sample test case.
Table 1: Explanation of Sample Test Case
. The sum of the
continuous medians is .
Subtasks
-
(10 points): ,
-
(10 points): ,
-
(40 points): ,
-
(40 points): ,
Sample Input 1 |
Sample Output 1 |
2
6
1 3 6 2 7 8
7
1 3 6 2 7 8 5
|
15
20
|