AC

许诺  •  4天前


#include <iostream>
#include <vector>
#include <climits>

using namespace std; int main() {

int N;
cin >> N;
vector<int> weights(N);
for (int i = 0; i < N; ++i) {
    cin >> weights[i];
}
int max_sum = INT_MIN;
int result_depth = 1;
int current_depth = 1;
int start_index = 0;

while (start_index < N) {
    int level_nodes = 1 << (current_depth - 1);
    int end_index = start_index + level_nodes;
    if (end_index > N) {
        end_index = N;
    }
    
    int sum = 0;
    for (int i = start_index; i < end_index; ++i) {
        sum += weights[i];
    }
    
    if (sum > max_sum) {
        max_sum = sum;
        result_depth = current_depth;
    }
    
    start_index = end_index;
    current_depth++;
}

cout << result_depth << endl;
return 0;

}


评论:

请先登录,才能进行评论