Using Priority_Queue solution C++


#1

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

int size = A.size();
priority_queue<int> pq;
for(int i=0;i<size;i++){
    pq.push(A[i]);
}
int res = 0;
while(B){
    int x = pq.top();
    res += x;
    pq.pop();
    pq.push(x-1);
    B--;
}
return res;

}