当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6645:Stay Real

题目描述
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.
输入解释
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$.
输出解释
For each test case, print a single line containing two integers $S$ and $E$, denoting the final score of Sunset and Elephant.
输入样例
1
3
1 2 3
输出样例
4 2
来自杭电HDUOJ的附加信息
Recommend liuyiding

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6645

最后修改于 2020-10-25T23:33:07+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 524288/524288K(Java/Others)