Maximal Score After Applying K Operations

Medium Topics Company Tags

Perform exactly k operations on the positive integer array nums. Each operation chooses one index, adds its current value to your score, and replaces that value with its value divided by 3, rounded upward to an integer. The same index may be chosen repeatedly. Starting from a score of zero, return the largest total score you can obtain.

Example 1:

Input: nums = [9,3]
k = 2

Output: 12

Explanation: Choose 9 first, earning 9 and replacing it with 3. Both entries are now 3, so the second operation earns 3. The maximum total is 12.

Example 2:

Input: nums = [2]
k = 4

Output: 5

Explanation: The only entry changes from 2 to 1 after the first operation and then stays 1. The four operations earn 2, 1, 1, and 1, totaling 5.

Example 3:

Input: nums = [4,4]
k = 3

Output: 10

Explanation: Choose each 4 once, earning 8 and leaving [2,2]. The last operation earns 2, so the total is 10.

Constraints:

  • 1 <= nums.length, k <= 100000
  • 1 <= nums[i] <= 1000000000


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.