commit 4afb9e20130e7d4ba85d23741ce5959eb09ef0af
parent f243a7fc3cdf5fc8ddce6998fd2f92381ed3068f
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Sat, 1 Jul 2023 18:10:46 +0200
Daily Problem
Diffstat:
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/Problems/2305.cpp b/Problems/2305.cpp
@@ -0,0 +1,28 @@
+class Solution {
+ vector<int> children = vector(8, 0);
+ int res = INT_MAX;
+
+ void rec(const vector<int> &cookies, vector<int> &children, int k, int cur,
+ int zero, int maxi = 0) {
+ if (cookies.size() - cur < zero) return;
+ if (cur >= cookies.size()) {
+ res = min(res, maxi);
+ return;
+ }
+
+ for (int i = 0; i < k; i++) {
+ zero -= children[i] == 0 ? 1 : 0;
+ children[i] += cookies[cur];
+ rec(cookies, children, k, cur + 1, zero, max(maxi, children[i]));
+ children[i] -= cookies[cur];
+ zero += children[i] == 0 ? 1 : 0;
+ }
+ }
+
+public:
+ int distributeCookies(const vector<int> &cookies, int k) {
+ vector<int> children = vector(k, 0);
+ rec(cookies, children, k, 0, k);
+ return res;
+ }
+};
diff --git a/README.md b/README.md
@@ -551,6 +551,7 @@ for solving problems.
| 2279 | Medium | [Maximum Bags With Full Capacity of Rocks](Problems/2279.cpp) |
| 2285 | Medium | [Maximum Total Importance of Roads](Problems/2285.cpp) |
| 2300 | Medium | [Successful Pairs of Spells and Potions](Problems/2300.cpp) |
+| 2305 | Medium | [Fair Distribution of Cookies](Problems/2305.cpp) |
| 2306 | Hard | [Naming a Company](Problems/2306.cpp) |
| 2316 | Medium | [Count Unreachable Pairs of Nodes in an Undirected Graph](Problems/2316.cpp) |
| 2326 | Medium | [Spiral Matrix IV](Problems/2326.cpp) |