Solution using max heap


#1

int Solution::nchoc(int A, vector &B) {
long long int ans=0;
const unsigned int M = 1000000007;
// max heap
priority_queue Q;
for( auto i: B )Q.push(i);

while(A --){
    int curr = Q.top();
    Q.pop();
    ans+= curr;
    Q.push(curr/2);

}
return ans%M;

}