public int maxCandies(int[] arr, int K) {
PriorityQueue<Integer> maxHeap = new PriorityQueue<Integer>(Comparator.reverseOrder());
for (int i : arr)
maxHeap.add(i);
int maxCandies = 0;
for (int i = 1; i <= K; i++) {
int rem = maxHeap.remove();
maxCandies += rem;
maxHeap.add(rem / 2);
}
return maxCandies;
}