O(nlogA) solution c++


#1

Comment bodint Solution::nchoc(int A, vector &B) {
int p = pow(10,9)+7;
priority_queue<int,vector,greater> minH;
priority_queuemaxH;
for(int i = 0;i<B.size();i++)
{
minH.push(B[i]);
if(minH.size()>A)
minH.pop();
}
while(minH.size()>0)
{
maxH.push(minH.top());
minH.pop();
}
int sum = 0;
for(int i = 0;i<A;i++)
{
int a= maxH.top();
sum=(sum%p+a%p)%p;
maxH.pop();
maxH.push(a/2);
}
return sum%p;
}
y goes here.