leetcode

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

commit a4658ed7d095488d07a55f092fc2788e2058ba99
parent 46b403d8ebf4091066e05173b7460d6f4ba7e78c
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sun, 29 Dec 2024 14:00:48 +0100

1 Random Problem

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

diff --git a/Problems/2931.cpp b/Problems/2931.cpp @@ -0,0 +1,21 @@ +class Solution { + public: + long long maxSpending(const vector<vector<int>> &values) const { + const int n = size(values), m = size(values[0]); + long long res = 0, add = 0; + static int vec[100001]; + + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + vec[m * i + j] = values[i][j]; + } + } + + sort(vec, vec + n * m, greater()); + for (int i = 0; i < n * m; i++) { + res += add += vec[i]; + } + + return res; + } +}; diff --git a/README.md b/README.md @@ -1447,6 +1447,7 @@ reference and a base for solving problems. | 2909 | Medium | [Minimum Sum of Mountain Triplets II](Problems/2909.cpp) | | 2914 | Medium | [Minimum Number of Changes to Make Binary String Beautiful](Problems/2914.cpp) | | 2924 | Medium | [Find Champion II](Problems/2924.cpp) | +| 2931 | Hard | [Maximum Spending After Buying Items](Problems/2931.cpp) | | 2938 | Medium | [Separate Black and White Balls](Problems/2938.cpp) | | 2940 | Hard | [Find Building Where Alice and Bob Can Meet](Problems/2940.cpp) | | 2947 | Medium | [Count Beautiful Substrings I](Problems/2947.cpp) |