Skip to content

Latest commit

 

History

History
27 lines (23 loc) · 563 Bytes

1760_minimumLimitOfBallsInABag.md

File metadata and controls

27 lines (23 loc) · 563 Bytes

Binary search on answer

Code

class Solution {
public:
    int minimumSize(vector<int>& nums, int maxOps)
    {
        int l = 1, r = 1e9;
        while (l < r) {
            int mid = l + (r - l) / 2;
            int cnt = 0;
            for (int x : nums)
                cnt += (x - 1) / mid;

            if (cnt > maxOps)
                l = mid + 1;
            else
                r = mid;
        }
        return l;
    }
};