# 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; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up