From 9e9bc7968a493d23582c9cb19b23114695d592e1 Mon Sep 17 00:00:00 2001 From: isaiahliu Date: Wed, 15 Jan 2025 13:39:22 +0800 Subject: [PATCH] 1 --- src/main/kotlin/p30xx/Problem3066.kt | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/kotlin/p30xx/Problem3066.kt diff --git a/src/main/kotlin/p30xx/Problem3066.kt b/src/main/kotlin/p30xx/Problem3066.kt new file mode 100644 index 00000000..2b59b66c --- /dev/null +++ b/src/main/kotlin/p30xx/Problem3066.kt @@ -0,0 +1,34 @@ +package p30xx + +import util.expect +import java.util.* + +fun main() { + class Solution { + fun minOperations(nums: IntArray, k: Int): Int { + val queue = PriorityQueue() + + nums.forEach { + queue.add(it.toLong()) + } + + var result = 0 + + while (queue.peek() < k) { + val n1 = queue.poll() + val n2 = queue.poll() ?: break + + queue.add(n1 * 2 + n2) + result++ + } + + + return result + } + } + expect { + Solution().minOperations( + intArrayOf(1), 1 + ) + } +}