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)


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