diff --git a/old-problems/2558/solution.cpp b/old-problems/2558/solution.cpp index eab703dd8..26ca7b2e8 100644 --- a/old-problems/2558/solution.cpp +++ b/old-problems/2558/solution.cpp @@ -1,8 +1,25 @@ +#include +#include #include class Solution { public: long long pickGifts(std::vector& gifts, int k) { - return gifts.size() * k; + std::priority_queue richest{}; + for (const auto gift : gifts) richest.push(gift); + + while (k > 0) { + richest.push(std::sqrt(richest.top())); + richest.pop(); + --k; + } + + long long total{0}; + while (!richest.empty()) { + total += richest.top(); + richest.pop(); + } + + return total; } };