public int minimizedMaximum(int n, int[] quantities) {
        int sum = 0;
        int r = 0;
        for (int quantity : quantities) {
            r = Math.max(quantity, r);
            sum += quantity;
        }
        if (sum == 0) {
            return 0;
        }
        int l = 1;
        int ans = Integer.MAX_VALUE;
        while (l <= r) {
            int mid = (r - l)/2 + l;
            if (isCorrect(quantities,n,mid)) {
                ans = Math.min(ans, mid);
                r = mid -1;
            }else{
                l = mid + 1;
            }
        }
        return ans;
    }

    public boolean isCorrect(int[] quantities ,int n ,int target) {
        for (int quantity : quantities) {
            n -= ((quantity + target - 1) / target);
        }
        return n >= 0;
    }