Skip to content

Commit bb212de

Browse files
committed
Add C++ solution of problem #2558
1 parent d4ae0fc commit bb212de

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

2558/solution.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
long long pickGifts(vector<int>& A, int k) {
4+
priority_queue<int> q(begin(A), end(A));
5+
for(int i = 0; i < k; i++) {
6+
int tmp = q.top();
7+
q.pop();
8+
tmp = sqrt(tmp);
9+
q.push(tmp);
10+
}
11+
12+
long long ans = 0LL;
13+
while(!q.empty()) {
14+
ans += q.top();
15+
q.pop();
16+
}
17+
return ans;
18+
}
19+
};

0 commit comments

Comments
 (0)