题目:1240. 完全二叉树的权值
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int >PII;
const int N=1e5+10;
const int mod=100000007;
int n;
int a[N];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
LL maxx=a[1];
int max_idx=1,idx=1;
int k=2;
while(k<=n){
LL res=0;
idx++;
while(k<(1<<idx)&&k<=n){
res+=a[k++];
}
if(maxx<res){
maxx=res;
max_idx=idx;
}
}
printf("%d",max_idx);
return 0;
}