Simple priority queue solution C++ STL


#1
int Solution::solve(vector<int> &A, int B) 
{
    priority_queue<int>pq;
    
    for(auto x:A)
    {
        pq.push(x);
    }
    
    int sum=0;
    while(B-- && pq.top()!=0)
    {
        int r=pq.top();
        sum=sum+r;
        pq.pop();
        pq.push(r-1);
    }
    
    return sum;
}