最后wa的两个点,是因为爆int了。。。
哭
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
struct node{
ll v=0;
int dep;
}a[N];
int n;
struct tree{
ll val=0;
int depth;
}b[N];
int k;
bool st[N];
bool cmp(tree aa, tree bb){
if(aa.val == bb.val){
return aa.depth < bb.depth;
}
return aa.val > bb.val;
}
int main(){
scanf("%d",&n);
for(int i = 1; i <= n; i++){
scanf("%lld",&a[i].v);
}
for(int i = 1; i <= n/2; i++){
if(i == 1) a[i].dep = 1;
if(i*2 <= n){
a[i * 2].dep = a[i].dep + 1;
}
if(i*2 + 1 <= n){
a[i*2 + 1].dep = a[i].dep + 1;
}
}
//for(int i = 1; i <= n; i++){
// cout << a[i].dep << " " << a[i].v<< endl;
// }
int mx = 0;
for(int i = 1; i <= n; i++){
b[a[i].dep].val += a[i].v;
b[a[i].dep].depth = a[i].dep;
mx = max(mx,a[i].dep);
}
sort(b + 1,b + mx + 1, cmp);
//cout <<"mx = " << mx << endl;
// for(int i = 1; i <= mx; i++){
// cout << b[i].depth <<" " << b[i].val << endl;
// }
cout << b[1].depth << endl;
return 0;
}