leetcode

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

2530.cpp (449B)


      1 class Solution {
      2   public:
      3     long long maxKelements(const vector<int> &nums, int k) const {
      4         priority_queue<int> pq(begin(nums), end(nums));
      5         long long res = 0;
      6 
      7         while (k--) {
      8             int crnt = pq.top();
      9             res += crnt;
     10             if (crnt == 1) {
     11                 res += k;
     12                 break;
     13             }
     14             pq.pop();
     15             pq.push((crnt + 2) / 3);
     16         }
     17 
     18         return res;
     19     }
     20 };