C++ solution using MaxHeap


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