AcWing 1240. 完全二叉树的权值
原题链接
简单
作者:
文氘
,
2024-04-08 20:58:17
,
所有人可见
,
阅读 1
#include<iostream>
#include<math.h>
using namespace std;
const int N=1e5+10;
typedef long long LL;
LL maxn=-100000;
LL a[N];
LL res;
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
a[i]+=a[i-1];
}
LL i;
for(i=1;pow(2,i)-1<=n;i++){
LL sum=a[(int)pow(2,i)-1]-a[(int)pow(2,i-1)-1];
if(sum>maxn){
res=i;
maxn=sum;
}
}
/**/
if(n>=pow(2,i-1)&&n<pow(2,i)-1){
LL sum=a[n]-a[(int)pow(2,i-1)-1];
if(sum>maxn){
res=i;
}
}
cout<<res;
return 0;
}