Skip to content

Commit 6e3400f

Browse files
committed
Medium
1 parent b00c4c6 commit 6e3400f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎Med2530.java

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import java.util.Collections;
2+
import java.util.PriorityQueue;
3+
import java.util.Queue;
4+
5+
class Med2530 {
6+
public long maxKelements(int[] nums, int k) {
7+
long ans = 0;
8+
Queue<Integer> maxHeap = new PriorityQueue<>(Collections.reverseOrder());
9+
10+
for (final int num : nums)
11+
maxHeap.offer(num);
12+
13+
for (int i = 0; i < k; ++i) {
14+
final int num = maxHeap.poll();
15+
ans += num;
16+
maxHeap.offer((num + 2) / 3);
17+
}
18+
19+
return ans;
20+
}
21+
}
22+

0 commit comments

Comments
 (0)