From 62a0ea3d50a1c2a87cd6f2540206a63bdfd2ec48 Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Sat, 7 Dec 2024 23:58:08 +0530 Subject: [PATCH] Create 1760. Minimum Limit of Balls in a Bag --- 1760. Minimum Limit of Balls in a Bag | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 1760. Minimum Limit of Balls in a Bag diff --git a/1760. Minimum Limit of Balls in a Bag b/1760. Minimum Limit of Balls in a Bag new file mode 100644 index 0000000..07c02ed --- /dev/null +++ b/1760. Minimum Limit of Balls in a Bag @@ -0,0 +1,13 @@ +class Solution { +public: + int minimumSize(vector& nums, int maxOps) { + int low = 1, high = *max_element(nums.begin(), nums.end()); + while (low < high) { + int mid = low + (high - low) / 2; + int ops = 0; + for (int n : nums) if ((ops += (n - 1) / mid) > maxOps) break; + ops <= maxOps ? high = mid : low = mid + 1; + } + return high; + } +};