Skip to content

Commit 50cffa6

Browse files
committed
add 2558
1 parent 7d1c17a commit 50cffa6

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
2558. Take Gifts From the Richest Pile
3+
4+
LeetCode Daily Question for December 12, 2024
5+
6+
Runtime: 0 ms (beats 100.00%)
7+
Memory: 13.26 MB (beats 36.35%)
8+
*/
9+
10+
class Solution {
11+
public:
12+
long long pickGifts(vector<int>& gifts, int k) {
13+
priority_queue<int> pq = { gifts.begin(), gifts.end() };
14+
for (int i = 0; i < k; ++i) {
15+
int temp = pq.top();
16+
pq.pop();
17+
pq.push(sqrt(temp));
18+
}
19+
long long sum = 0;
20+
while (!pq.empty()) {
21+
sum += pq.top();
22+
pq.pop();
23+
}
24+
return sum;
25+
}
26+
};

0 commit comments

Comments
 (0)