Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e81ef3a

Browse files
committed
Time: 1 ms (68.38%), Space: 13.1 MB (62.09%) - LeetHub
1 parent b895c19 commit e81ef3a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
long long pickGifts(vector<int>& gifts, int k) {
4+
priority_queue<long long> pq;
5+
6+
for(auto it : gifts) pq.push(it);
7+
8+
while(k--){
9+
long long temp = pq.top();
10+
pq.pop();
11+
temp = (long long)sqrt(temp);
12+
pq.push(temp);
13+
}
14+
15+
long long res = 0;
16+
17+
while(!pq.empty()){
18+
res+=pq.top();
19+
pq.pop();
20+
}
21+
return res;
22+
}
23+
};

0 commit comments

Comments
 (0)