Simple c++ solution using maxheap (efficient)


#1

vector Solution::solve(vector &A, int B) {

priority_queue<int>q;
int n=A.size();
 vector<int>m; 

// while(B–)
for(int i=0;i<n;i++)
{
q.push(A[i]);
}

for(int i=0;i<B;i++)
{
   
        //q.pop();
        m.push_back(q.top());
        q.pop();
    //}
}

// m.push_back(q.top());

return m;
//q.top();

}