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; + } +};