File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 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+ };
You can’t perform that action at this time.
0 commit comments