You're given an array of positive integers nums and an integer k representing the maximum number of operations you can perform. Your goal is to maximize the score of any contiguous subarray after applying strategic modifications.
Operations Available:
- You can perform at most
koperations - Each operation doubles the value of any element in the array
- Each element can be doubled at most once
Subarray Score Calculation:
The score of a contiguous subarray equals: Length ร GCD(all elements in subarray)
Where GCD is the Greatest Common Divisor - the largest integer that evenly divides all elements in the subarray.
Your Task: Return the maximum possible score achievable by selecting any contiguous subarray from the strategically modified array.
Example: For nums = [12, 18, 6], k = 1, if we double the element 6 to get [12, 18, 12], the subarray [12, 18, 12] has GCD = 6 and length = 3, giving score = 18.
Input & Output
Constraints
- 1 โค nums.length โค 100
- 1 โค nums[i] โค 106
- 0 โค k โค nums.length
- Each element can be doubled at most once
- All array elements are positive integers