# 2558. Take Gifts From the Richest Pile ###### tags: `Leetcode` `Easy` Link: https://leetcode.com/problems/take-gifts-from-the-richest-pile/description/ ## Code ```java= class Solution { public long pickGifts(int[] gifts, int k) { long ans = 0; Queue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder()); for(int i=0; i<gifts.length; i++){ pq.add(gifts[i]); } for(int i=0; i<k; i++){ pq.add((int)(Math.sqrt(pq.poll()))); } while(!pq.isEmpty()) ans += pq.poll(); return ans; } } ```