From 613bd19cfdefe7eb35eb2db1f8d8caf72fdc03ad Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:55:59 +0530 Subject: [PATCH] Create 2064. Minimized Maximum of Products Distributed to Any Store --- ...ximum of Products Distributed to Any Store | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 2064. Minimized Maximum of Products Distributed to Any Store diff --git a/2064. Minimized Maximum of Products Distributed to Any Store b/2064. Minimized Maximum of Products Distributed to Any Store new file mode 100644 index 0000000..dc54180 --- /dev/null +++ b/2064. Minimized Maximum of Products Distributed to Any Store @@ -0,0 +1,27 @@ +class Solution { +public: + int check(int val, vector& nums, int n) { + int cnt = 0; + for (int i = 0; i < nums.size(); i++) { + cnt += (nums[i] + val - 1) / val; + } + return cnt; + } + + int minimizedMaximum(int n, vector& quantities) { + int h = 1e5; + int l = 1; + int ans = -1; + + while (l <= h) { + int mid = l + (h - l) / 2; + if (check(mid, quantities, n) <= n) { + ans = mid; + h = mid - 1; + } else { + l = mid + 1; + } + } + return ans; + } +};