Easy C++ STL priority queue solution


#1

int Solution::solve(vector &A, int B) {
priority_queue q;
int i,c=0;
for(i=0;i<A.size();i++){
q.push(A[i]);
}
int profit=0;
while(c<B){
int x=q.top();
q.pop();
if(x==0)break;

    profit+=x;
    q.push(x-1);
    c++;
    
}
return profit;

}