You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/2500-2599/2530.Maximal Score After Applying K Operations/README_EN.md
+52-5
Original file line number
Diff line number
Diff line change
@@ -49,6 +49,14 @@ The final score is 10 + 4 + 3 = 17.
49
49
50
50
## Solutions
51
51
52
+
**Solution 1: Priority Queue (Max Heap)**
53
+
54
+
To maximize the sum of scores, we need to select the element with the maximum value at each step. Therefore, we can use a priority queue (max heap) to maintain the element with the maximum value.
55
+
56
+
At each step, we take out the element with the maximum value $v$ from the priority queue, add $v$ to the answer, and replace $v$ with $\lceil \frac{v}{3} \rceil$, and then add it to the priority queue. After repeating this process $k$ times, we return the answer.
57
+
58
+
The time complexity is $O(n + k \times \log n)$, and the space complexity is $O(n)$ or $O(1)$. Here, $n$ is the length of the array $nums$.
0 commit comments