Problem 3028 --Stay Real

3028: Stay Real

"
Time Limit $1$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $1$ 正确数量 $0$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
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 CC, if PP is a parent node of CC, then the key(the value) of PP is less than or equal to the key of CC. The node at the ``top'' of the heap(with no parents) is called the root node. 

Usually, we may store a heap of size nn in an array h1,h2,…,hnh1,h2,…,hn, where hihi denotes the key of the ii-th node. The root node is the 11-th node, and the parent of the i(2≤i≤n)i(2≤i≤n)-th node is the ⌊i2⌋⌊i2⌋-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≤T≤10000)T(1≤T≤10000), denoting the number of test cases. 

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

In the second line, there are nn integers h1,h2,...,hn(1≤hi≤109,h⌊i2⌋≤hi)h1,h2,...,hn(1≤hi≤109,h⌊i2⌋≤hi), denoting the key of each node. 

It is guaranteed that ∑n≤106∑n≤106.
For each test case, print a single line containing two integers SS and EE, denoting the final score of Sunset and Elephant.
1
3
1 2 3
4 2

推荐代码 查看3028 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$ $ms]
内存最少[$ $KB]
第一AC
第一挑战 淡意的温柔 588045 2020-05-27 09:32:05

赛题来源/所属竞赛 2019 Multi-University Training Contest 6 N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛