1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| class Solution { public long maxKelements(int[] nums, int k) { long score = 0;
Queue<Integer> maxHeap = new PriorityQueue<>((o1, o2) -> Integer.compare(o2, o1)); for (int num : nums) { maxHeap.offer(num); } for (int i = 0; i < k && !maxHeap.isEmpty(); i++) { int num = maxHeap.poll(); score += num; maxHeap.offer((num + 2) / 3); }
return score; } }
|
References
2530. Maximal Score After Applying K Operations