677. Maximal Score After Applying K Operations

HardStackHeapGreedy

Given an array nums and an integer k, perform k operations. Each operation picks the current maximum element, adds it to your score, and replaces that element with ceil(value / 3). Return the maximum score after k operations. The input is JSON {nums, k}.

Input: JSON {nums, k}.

Output: Integer — the maximum score.

Examples

Example 1
Input: {"nums":[10,10,10,10,10],"k":5}
Output: 50
Explanation: Take each 10 once.
Example 2
Input: {"nums":[1,10,3,3,3],"k":3}
Output: 17
Explanation: 10 + 4 + 3.
Example 3
Input: {"nums":[5],"k":1}
Output: 5
Explanation: One operation.

Constraints

Asked by

BloombergAmazonGoogle
Solve this problem in the editor →