```
int Solution::solve(vector<int> &A, int B) {
priority_queue<int> pq;
if(A.size() == 0) return 0; // base
for(int i = 0; i<A.size()-1; i++){
int profit = 0;
if(A[i+1] > A[i]){
profit = A[i+1] - A[i];
pq.push(profit);
}
}
int ans = 0;
while(B > 0 && !pq.empty()){
ans+=pq.top();
pq.pop();
B--;
}
return ans;
}
```

This was my own attempt to solve this sum…and all custom test cases are satisfied. Where am I going wrong?