#P8681. [蓝桥杯 2019 省 AB] 完全二叉树的权值

[蓝桥杯 2019 省 AB] 完全二叉树的权值

Description

Given a complete binary tree with NN nodes, each node has a weight. In the order from top to bottom and from left to right, the weights are A1,A2,,ANA_1, A_2, \cdots, A_N, as shown in the figure below:

Now Xiaoming wants to add up the weights of nodes at the same depth. He wants to know at which depth the sum of node weights is the largest. If there are multiple depths whose sums are tied for the largest, output the smallest such depth.

Note: The depth of the root is 11.

Input Format

The first line contains an integer NN.

The second line contains NN integers A1,A2,,ANA_1, A_2, \cdots, A_N.

Output Format

Output one integer representing the answer.

7
1 6 5 4 3 2 1
2

Hint

For all testdata, 1N1051 \le N \le 10^5, and 0Ai1050 \le |A_i| \le 10^5.

Lanqiao Cup 2019 NOI Qualifier, Group A Problem F (Group B Problem G).

Translated by ChatGPT 5