C++ solution using priority queue and long long int use


#1

int Solution::nchoc(int n, vector &v)
{
//sort(v.begin(),v.end(),greater());
priority_queuepq;

for(int i=0;i<v.size();i++)
{
    pq.push(v[i]);
}
long long sum=0;

while(n>0)
{
    int temp=pq.top();
    int num=pq.top();
    sum=(sum+num);
    pq.pop();
    pq.push(num/2);
    n--;
}
int temp=sum%1000000007;
return temp;

}