Using make_heap() stl in c++


#1

int Solution::solve(vector &v, int n)
{

make_heap(v.begin(),v.end());
int sum=0;

while(n--)
{
    int k =v.front();
    
    pop_heap(v.begin(),v.end());
    
    
    v.pop_back();
    sum=sum+k;
    v.push_back(k-1);
    push_heap(v.begin(),v.end());

}

return sum;

}