Minimum Limit of Balls in a Bag
You are given an integer array nums where the i^th bag contains nums[i] balls. You are also given an integer maxOperations.
You can perform the following operation at most maxOperations times:
- Take any bag of balls and divide it into two new bags with a positive number of balls.
- For example, a bag of
5balls can become two new bags of1and4balls, or two new bags of2and3balls.
Your penalty is the maximum number of balls in a bag. You want to minimize your penalty after the operations.
Return the minimum possible penalty after performing the operations.
Example 1
Input
nums = [9], maxOperations = 2Output
3After splitting 9 into 6 and 3, then splitting 6 into 3 and 3, the maximum number of balls in any bag is 3.
Example 2
Input
nums = [2,4,8,2], maxOperations = 4Output
2By splitting the bag with 8 into two 4s and then splitting each 4 into two 2s, every bag has at most 2 balls.
Constraints
- 1 <= nums.length <= 10^5
- 1 <= maxOperations, nums[i] <= 10^9