We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 45cc82d + 9a6da5b commit 08b82acCopy full SHA for 08b82ac
2558. Take Gifts From the Richest Pile1
@@ -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
12
+ gifts[m]=a;
13
+ }
14
+ for(int i : gifts){
15
+ ans+=i;
16
17
+ return ans;
18
19
+};
20
+
21
+class Solution {
22
23
24
25
+ priority_queue<int> vp;
26
+ for(int i : gifts) vp.push(i);
27
28
+ int a=vp.top();
29
+ vp.pop();
30
31
32
33
+ vp.push(a);
34
35
+ while(!vp.empty()){
36
+ ans+=vp.top();
37
38
39
40
41
0 commit comments