commit 4520be275682245aaf9c1e1e761bfd9f631171e8
parent 0b21a92e31935b3f3b65f45f74b4231b96d9d72d
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Sat, 8 Jul 2023 22:46:09 +0200
Daily Problem
Diffstat:
2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/Problems/2551.cpp b/Problems/2551.cpp
@@ -0,0 +1,15 @@
+class Solution {
+public:
+ long long putMarbles(vector<int> &weights, int k) {
+ long long res = 0, n = weights.size();
+
+ for (int i = 0; i < n - 1; i++) weights[i] += weights[i + 1];
+
+ weights.resize(n - 1);
+ sort(weights.begin(), weights.end());
+
+ for (int i = 0; i < k - 1; i++) res += weights[n - 2 - i] - weights[i];
+
+ return res;
+ }
+};
diff --git a/README.md b/README.md
@@ -585,6 +585,7 @@ for solving problems.
| 2492 | Medium | [Minimum Score of a Path Between Two Cities](Problems/2492.cpp) |
| 2497 | Medium | [Maximum Star Sum of a Graph](Problems/2497.cpp) |
| 2542 | Medium | [Maximum Subsequence Score](Problems/2542.cpp) |
+| 2551 | Hard | [Put Marbles in Bags](Problems/2551.cpp) |
| 2620 | Easy | [Counter](Problems/2620.js) |
| 2621 | Easy | [Sleep](Problems/2621.js) |
| 2622 | Medium | [Cache With Time Limit](Problems/2622.js) |