AmazonOA #375
Get Priorities after Execution
估计困难可在线判题
In each round, find the largest priority p that occurs at least twice; stop if none exists or p=0. Take the first two items with that priority in the current queue, delete the first one, and reduce the second one to floor(p/2). The relative order of everything else is unchanged. Output the final queue.
输入格式
The first line contains n, and the second line contains n initial priorities. Original bounds: 1≤n≤100000, 1≤initial priority≤10^9; 0 may appear during processing, but 0s cannot be merged further.
输出格式
The first line is the final length; the second line is the final priorities in their original relative order.
样例 1
输入:
6
6 6 6 1 2 2
输出:
3
3 6 0
样例 2
输入:
4
4 4 2 1
输出:
1
0
样例 3
输入:
6
2 1 5 10 10 1
输出:
2
0 1
样例说明
The outputs are the 3 numbers 3 6 0, the single number 0, and the 2 numbers 0 1, respectively. In the original second example, the first intermediate queue should be 2 2 1; the 17 in the walkthrough of the third example is a typo, and the last original item stays 1 throughout.