leetcode

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

commit b723eb133dfb085cc2894fbd35e92857bb2c90d1
parent 897de71ae7774fef9e5ea0f037ffd4aa0ceb382f
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Mon, 14 Oct 2024 13:40:28 +0200

Daily Problem

Diffstat:
AProblems/2530.cpp | 20++++++++++++++++++++
MREADME.md | 1+
2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/Problems/2530.cpp b/Problems/2530.cpp @@ -0,0 +1,20 @@ +class Solution { + public: + long long maxKelements(const vector<int> &nums, int k) const { + priority_queue<int> pq(begin(nums), end(nums)); + long long res = 0; + + while (k--) { + int crnt = pq.top(); + res += crnt; + if (crnt == 1) { + res += k; + break; + } + pq.pop(); + pq.push((crnt + 2) / 3); + } + + return res; + } +}; diff --git a/README.md b/README.md @@ -1254,6 +1254,7 @@ for solving problems. | 2517 | Medium | [Maximum Tastiness of Candy Basket](Problems/2517.cpp) | | 2526 | Medium | [Find Consecutive Integers from a Data Stream](Problems/2526.cpp) | | 2527 | Medium | [Find Xor-Beauty of Array](Problems/2527.cpp) | +| 2530 | Medium | [Maximal Score After Applying K Operations](Problems/2530.cpp) | | 2536 | Medium | [Increment Submatrices by One](Problems/2536.cpp) | | 2537 | Medium | [Count the Number of Good Subarrays](Problems/2537.cpp) | | 2540 | Easy | [Minimum Common Value](Problems/2540.cpp) |