leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2558.cpp (419B)


      1 class Solution {
      2   public:
      3     long long pickGifts(const vector<int> &gifts, int k) const {
      4         priority_queue<int> pq(begin(gifts), end(gifts));
      5         long long remain = accumulate(begin(gifts), end(gifts), 0ll);
      6 
      7         while (k--) {
      8             const int crnt = pq.top(), leave = sqrt(crnt);
      9             pq.pop(), pq.push(leave);
     10             remain -= crnt - leave;
     11         }
     12 
     13         return remain;
     14     }
     15 };