AC

许诺 · 发布于 2025-08-08 · 浏览 341 回复 0
	#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;
}

全部回复 共 0 条

还没有人回复。往下写第一条。

发表回复