leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
2558.cpp (419B)
0 class Solution {
1 public:
2 long long pickGifts(const vector<int> &gifts, int k) const {
3 priority_queue<int> pq(begin(gifts), end(gifts));
4 long long remain = accumulate(begin(gifts), end(gifts), 0ll);
6 while (k--) {
7 const int crnt = pq.top(), leave = sqrt(crnt);
8 pq.pop(), pq.push(leave);
9 remain -= crnt - leave;
10 }
12 return remain;
13 }
14 };