Skip to content

Commit dd12772

Browse files
authored
Create 2558. Take Gifts From the Richest Pile (#663)
2 parents 493cf81 + fb8069d commit dd12772

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public:
3+
#define P pair<int,int>
4+
vector<int> getFinalState(vector<int>& nums, int k, int multiplier) {
5+
priority_queue<P,vector<P>,greater<P>>pq;
6+
vector<int>ans(nums.size(),0);
7+
for(int i = 0;i<nums.size();i++){
8+
pq.push({nums[i],i});
9+
}
10+
while(k>0){
11+
auto n = pq.top();
12+
pq.pop();
13+
n.first*=multiplier;
14+
pq.push({n.first,n.second});
15+
k--;
16+
}
17+
18+
while(!pq.empty()){
19+
auto n = pq.top();
20+
int idx= n.second;
21+
int ele= n.first;
22+
ans[idx]=ele;
23+
pq.pop();
24+
}
25+
return ans;
26+
}
27+
};

0 commit comments

Comments
 (0)