You are given an array of positive integers `rates` of length `n`, and an integer `k`. You need to find the minimum positive integer threshold `M` such that the sum of ceil(rates[i] / M) for all 0 <= i < n is less than or equal to `k`. Here, ceil(x) represents the ceiling function, which returns the smallest integer greater than or equal to x. If no such positive integer `M` exists (which occurs when `k` is less than `n`), return -1.
Explanation: With M = 3, the sum of ceiling divisions is ceil(3/3) + ceil(6/3) + ceil(7/3) = 1 + 2 + 3 = 6, which is <= 8. For M = 2, the sum is 9, which exceeds 8.
Analyze constraints and compute optimal solutions step-by-step.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak