Easy C++ solution using Heap


#1
int Solution::solve(vector<int> &A, int B) 
{
    priority_queue<int>q;
    for(int i=0;i<A.size();i++)
    {
        q.push(A[i]);
    }
    int count=0,sum=0;
    while(count<B)
    {
        sum+=q.top();
        int x=q.top();
        q.pop();
        q.push(x-1);
        count++;
    }
    return sum;
}