Simple solution - std::priority_queue


#1
int Solution::nchoc(int A, vector<int> &B) {
    
    std::priority_queue<int> bag_sizes; 
    
    for (int initial_size : B) {
        bag_sizes.push(initial_size);
    }
    
    int result = 0;
    
    for (int i = 0; i < A; i++) {
        int largest = bag_sizes.top();
        if (largest == 0) { break; }
        result += largest;
        bag_sizes.pop();
        bag_sizes.push(largest / 2);
    }
    
    return result % static_cast<int>(std::pow(10, 9) + 7);
}

#2

Giving wrong answer, use long long for result.