Maximum Bitwise AND After Increment Operations
You are given an integer array nums and two integers k and m.
You may perform at most k operations. In one operation, you may choose any index i and increase nums[i] by 1.
Return an integer denoting the maximum possible bitwise AND of any subset of size m after performing up to k operations optimally.
Example 1
Input
nums = [3,1,2], k = 8, m = 2Output
6Choose indices [0, 2], increase nums[0] from 3 to 6 using 3 operations and nums[2] from 2 to 6 using 4 operations, so the chosen values become [6, 6] with bitwise AND 6.
Example 2
Input
nums = [1,2,8,4], k = 7, m = 3Output
4Choose indices [0, 1, 3], increase nums[0] from 1 to 4 using 3 operations, nums[1] from 2 to 4 using 2 operations, and keep nums[3] as 4, so the chosen values become [4, 4, 4] with bitwise AND 4.
Constraints
- 1 <= n == nums.length <= 5 * 10^4
- 1 <= nums[i] <= 10^9
- 1 <= k <= 10^9
- 1 <= m <= n