From 53d7d4105edadcbadb46ded5b8163335a833508d Mon Sep 17 00:00:00 2001 From: isaiahliu Date: Thu, 12 Dec 2024 00:49:34 +0800 Subject: [PATCH] 1 --- src/main/kotlin/p29xx/Problem2931.kt | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/main/kotlin/p29xx/Problem2931.kt diff --git a/src/main/kotlin/p29xx/Problem2931.kt b/src/main/kotlin/p29xx/Problem2931.kt new file mode 100644 index 00000000..acdea650 --- /dev/null +++ b/src/main/kotlin/p29xx/Problem2931.kt @@ -0,0 +1,39 @@ +package p29xx + +import util.expect +import java.util.* + +fun main() { + class Solution { + fun maxSpending(values: Array): Long { + val queue = PriorityQueue>(compareBy { (r, c) -> values[r][c] }) + + values.indices.forEach { + queue.add(it to values[it].lastIndex) + } + + var day = 1L + var result = 0L + + while (queue.isNotEmpty()) { + val (r, c) = queue.poll() + + result += values[r][c] * day + + if (c > 0) { + queue.add(r to c - 1) + } + + day++ + } + + return result + } + } + + expect { + Solution().maxSpending( + arrayOf() + ) + } +}