class Solution { public long maxKelements(int[] nums, int k) { PriorityQueue<Integer> priorityQueue = new PriorityQueue<>((num1, num2) -> num2 - num1); for (int num : nums) { priorityQueue.offer(num); } long ans = 0; for (int i = 0; i < k; i++) { int num = priorityQueue.poll(); ans += num; priorityQueue.offer((num + 2) / 3); } return ans; } }