Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
isaiahliu committed Dec 11, 2024
1 parent ea7c010 commit 53d7d41
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/main/kotlin/p29xx/Problem2931.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package p29xx

import util.expect
import java.util.*

fun main() {
class Solution {
fun maxSpending(values: Array<IntArray>): Long {
val queue = PriorityQueue<Pair<Int, Int>>(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()
)
}
}

0 comments on commit 53d7d41

Please sign in to comment.