Easy cpp solution using priority queue(max heap)


#1
int Solution::solve(vector<int> &a, int b) {
priority_queue<int>pq;
for(auto i:a)
pq.push(i);
int ans=0;
while(b-- && !pq.empty())
{
    ans+=pq.top();
    int k=pq.top();
    pq.pop();
    k--;
    if(k>0)
    pq.push(k);
}
return and;
}