2530. Maximal Score After Applying K Operations

problem

solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
public:
long long maxKelements(vector<int>& nums, int k) {
long long ret = 0 ;
// select max value in vector
priority_queue <int> pq;
for(int n:nums) pq.push(n);
while(k--){
double t =pq.top();
ret+=t;
pq.pop();
pq.push(ceil(t/3));
}
return ret;

}
};

analysis

  • time complexity O(Klogn) , K is the number of query
  • space complexity O(n)