diff --git a/solutions/day14/solution_java.java b/solutions/day14/solution_java.java new file mode 100644 index 0000000..c71e888 --- /dev/null +++ b/solutions/day14/solution_java.java @@ -0,0 +1,16 @@ +class Solution { + public long maxKelements(int[] nums, int k) { + long score = 0; + Queue pq = new PriorityQueue<>((a, b) -> b-a); + for(int num: nums) { + pq.add(num); + } + int peek; + while(k-- > 0) { + peek = pq.poll(); + score += peek; + pq.add((peek+2)/3); + } + return score; + } +}