Skip to content

Commit 08b82ac

Browse files
authored
Create 2558. Take Gifts From the Richest Pile1 (#659)
2 parents 45cc82d + 9a6da5b commit 08b82ac

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
class Solution1 {
2+
public:
3+
long long pickGifts(vector<int>& gifts, int k) {
4+
long long ans=0;
5+
for(int i=0;i<k;i++){
6+
int m=0;
7+
for(int j=1;j<gifts.size();j++) if(gifts[j]>gifts[m]) m=j;
8+
int a=gifts[m];
9+
// cout<<a<<endl;
10+
a=sqrt(a);
11+
// cout<<a<<endl;
12+
gifts[m]=a;
13+
}
14+
for(int i : gifts){
15+
ans+=i;
16+
}
17+
return ans;
18+
}
19+
};
20+
21+
class Solution {
22+
public:
23+
long long pickGifts(vector<int>& gifts, int k) {
24+
long long ans=0;
25+
priority_queue<int> vp;
26+
for(int i : gifts) vp.push(i);
27+
for(int i=0;i<k;i++){
28+
int a=vp.top();
29+
vp.pop();
30+
// cout<<a<<endl;
31+
a=sqrt(a);
32+
// cout<<a<<endl;
33+
vp.push(a);
34+
}
35+
while(!vp.empty()){
36+
ans+=vp.top();
37+
vp.pop();
38+
}
39+
return ans;
40+
}
41+
};

0 commit comments

Comments
 (0)