AcWing 1240. 完全二叉树的权值
原题链接
简单
作者:
Sundae
,
2019-12-25 15:42:48
,
所有人可见
,
阅读 945
#include<iostream>
#include <algorithm>
using namespace std;
const int maxn = 100000 + 100;
int a[maxn];
int main(){
int n;
cin >> n;
for(int i = 1; i <= n; ++i){
cin >> a[i];
}
int ans = -1;
int max = -9999999999999;
int k = 0;
for(int i = 1; i <= n; i = i * 2){
k ++;
long long int sum = 0;
for(int j = i; j <= 2 * i - 1 ; ++j){
if(j <= n)
sum += a[j];
}
//cout << sum << endl;
if(sum > max){
max = sum;
ans = k;
}
}
cout << ans << endl;
return 0;
}