Python 代码
if __name__=='__main__':
n = int(input())
a = list(map(int, input().split()))
sum=[0]*(n+1)
for i in range(1,n+1):
sum[i]=sum[i-1]+a[i-1]
weight = -1e18
height=0#存结果
depth=1 #当前的层数
point=2 #标点
while point<=n: #把point作为前标,防止超下表
if sum[point-1]-sum[point//2-1]>weight:
height=depth
weight=sum[point-1]-sum[point//2-1]
depth+=1
point*=2
#最后判一下剩下的
if sum[n]-sum[point//2-1]>weight:
height=depth
print(height)