leetcode

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

commit b2c8b0357da884fdb63366fd0605a1f5cb15832f
parent 253e75ebe7bb220916faa5ca981305a422caec32
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Thu,  9 May 2024 12:40:42 +0200

Daily Problem

Diffstat:
AProblems/3075.cpp | 14++++++++++++++
MREADME.md | 1+
2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/Problems/3075.cpp b/Problems/3075.cpp @@ -0,0 +1,14 @@ +class Solution { + public: + long long maximumHappinessSum(vector<int> &happiness, int k) const { + long long res = 0; + + nth_element(begin(happiness), begin(happiness) + k, end(happiness), greater()); + sort(begin(happiness), begin(happiness) + k, greater()); + + for (int i = 0; i < k; i++) + res += max(happiness[i] - i, 0); + + return res; + } +}; diff --git a/README.md b/README.md @@ -1217,6 +1217,7 @@ for solving problems. | 3039 | Medium | [Apply Operations to Make String Empty](Problems/3039.cpp) | | 3067 | Medium | [Count Pairs of Connectable Servers in a Weighted Tree Network](Problems/3067.cpp) | | 3070 | Medium | [Count Submatrices with Top-Left Element and Sum Less Than k](Problems/3070.cpp) | +| 3075 | Medium | [Maximize Happiness of Selected Children](Problems/3075.cpp) | | 3100 | Medium | [Water Bottles II](Problems/3100.cpp) | | 3101 | Medium | [Count Alternating Subarrays](Problems/3101.cpp) | | 3106 | Medium | [Lexicographically Smallest String After Operations With Constraint](Problems/3106.cpp) |