---
# System prepended metadata

title: 2558. Take Gifts From the Richest Pile
tags: [Leetcode]

---

<style>
    html, body, .ui-content {
    background: #222222;
    color: #00BFFF;
}
    /* 設定 code 模板 */
    .markdown-body code,
.markdown-body tt {
    background-color: #ffffff36;
}
.markdown-body .highlight pre,
.markdown-body pre {
    color: #ddd;
    background-color: #00000036;
}
.hljs-tag {
    color: #ddd;
}
.token.operator {
  background-color: transparent;
}    
/* 設定連結 */
a,
.open-files-container li.selected a {
    color: #89FFF8;
    
}
a:hover,
.open-files-container li.selected a:hover {
    color: #89FFF890;
}
   
</style>

###### tags: `Leetcode`

# 2558. Take Gifts From the Richest Pile


###### Link : https://leetcode.com/problems/take-gifts-from-the-richest-pile/description/

## 題目

## 程式碼
```cpp=
class Solution {
public:
    long long pickGifts(vector<int>& gifts, int k) {
        long long ans = 0;
        for(int i = 0;i < k;i++){
            auto it = max_element(gifts.begin(), gifts.end());
            *it = (int)sqrt(*it);
        }
        for(auto &it : gifts)
            ans += it;
        return ans;
    }
};
```

## Date 
### 2023/2/5