F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Stay Real

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1395    Accepted Submission(s): 775


Problem Description
In computer science, a heap is a specialized tree-based data structure which is essentially an almost complete tree that satisfies the heap property: in a min heap, for any given node $C$, if $P$ is a parent node of $C$, then the key(the value) of $P$ is less than or equal to the key of $C$. The node at the ``top'' of the heap(with no parents) is called the root node.

Usually, we may store a heap of size $n$ in an array $h_1,h_2,\dots,h_n$, where $h_i$ denotes the key of the $i$-th node. The root node is the $1$-th node, and the parent of the $i(2\leq i\leq n)$-th node is the $\lfloor\frac{i}{2}\rfloor$-th node.

Sunset and Elephant is playing a game on a min heap. The two players move in turns, and Sunset moves first. In each move, the current player selects a node which has no children, adds its key to this player's score and removes the node from the heap.

The game ends when the heap is empty. Both players want to maximize their scores and will play optimally. Please write a program to figure out the final result of the game.
 

Input
The first line of the input contains an integer $T(1\leq T\leq 10000)$, denoting the number of test cases.

In each test case, there is one integer $n(1\leq n\leq 100000)$ in the first line, denoting the number of nodes.

In the second line, there are $n$ integers $h_1,h_2,...,h_n(1\leq h_i\leq 10^9,h_{\lfloor\frac{i}{2}\rfloor}\leq h_i)$, denoting the key of each node.

It is guaranteed that $\sum n\leq 10^6$.
 

Output
For each test case, print a single line containing two integers $S$ and $E$, denoting the final score of Sunset and Elephant.
 

Sample Input
1 3 1 2 3
 

Sample Output
4 2
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 03:36:35, Gzip enabled