Class Solution
-
- All Implemented Interfaces:
public final class Solution2530 - Maximal Score After Applying K Operations\.
Medium
You are given a 0-indexed integer array
numsand an integerk. You have a starting score of0.In one operation:
choose an index
isuch that0 <= i < nums.length,increase your score by
nums[i], andreplace
nums[i]withceil(nums[i] / 3).
Return the maximum possible score you can attain after applying exactly
koperations.The ceiling function
ceil(val)is the least integer greater than or equal toval.Example 1:
Input: nums = 10,10,10,10,10, k = 5
Output: 50
Explanation: Apply the operation to each array element exactly once. The final score is 10 + 10 + 10 + 10 + 10 = 50.
Example 2:
Input: nums = 1,10,3,3,3, k = 3
Output: 17
Explanation: You can do the following operations:
Operation 1: Select i = 1, so nums becomes 1, **<ins>4</ins>** ,3,3,3. Your score increases by 10.
Operation 2: Select i = 1, so nums becomes 1, **<ins>2</ins>** ,3,3,3. Your score increases by 4.
Operation 3: Select i = 2, so nums becomes 1,1,<ins> **1** </ins>,3,3. Your score increases by 3.
The final score is 10 + 4 + 3 = 17.
Constraints:
<code>1 <= nums.length, k <= 10<sup>5</sup></code>
<code>1 <= numsi<= 10<sup>9</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final LongmaxKelements(IntArray nums, Integer k)-
-
Method Detail
-
maxKelements
final Long maxKelements(IntArray nums, Integer k)
-
-
-
-