complete 13265.kt 21208.kt

This commit is contained in:
2025-07-07 17:42:25 +09:00
parent 0406a80d8f
commit 5907d7f7c8
2 changed files with 92 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
data class Record(
var counts: Int,
var lastModified: Int,
)
fun main() = with(System.`in`.bufferedReader()) {
val (n, k) = readln().split(' ').map { i -> i.toInt() }
val history = mutableMapOf<String, Record>()
(1..(3 * n)).forEach { i ->
val key = readln()
if (key in history) {
history[key]?.let {
it.counts++
it.lastModified = i
}
} else {
history[key] = Record(1, i)
}
}
history.toList().sortedWith(compareBy({ it.second.counts }, { it.second.lastModified })).takeLast(k).reversed()
.forEach { item ->
println(item.first)
}
}