commit 997f1252e1dfce721a54792ed5ca3be273763d6b
parent bfdfa31f47e565abff74beaa62b216d8cce4ec7d
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Wed, 9 Aug 2023 23:38:11 +0200
Daily Problem
Diffstat:
2 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/Problems/2616.cpp b/Problems/2616.cpp
@@ -0,0 +1,23 @@
+class Solution {
+ int count(const vector<int> &nums, int treshold) {
+ int cnt = 0;
+ for (int i = 1; i < nums.size(); i++) {
+ if (nums[i] - nums[i - 1] <= treshold) cnt++, i++;
+ }
+ return cnt;
+ }
+
+public:
+ int minimizeMax(vector<int> &nums, int p) {
+ sort(nums.begin(), nums.end());
+ int left = 0, right = nums.back() - nums.front();
+ while (left < right) {
+ int mid = left + (right - left) / 2;
+ if (count(nums, mid) >= p)
+ right = mid;
+ else
+ left = mid + 1;
+ }
+ return left;
+ }
+};
diff --git a/README.md b/README.md
@@ -615,6 +615,7 @@ for solving problems.
| 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) |
+| 2616 | Medium | [Minimize the Maximum Difference of Pairs](Problems/2616.cpp) |
| 2620 | Easy | [Counter](Problems/2620.js) |
| 2621 | Easy | [Sleep](Problems/2621.js) |
| 2622 | Medium | [Cache With Time Limit](Problems/2622.js) |