fun main() { val (n, k) = readLine()!!.split(" ").map { it.toInt() } val p = readLine()!!.split(" ").map { it.toInt() }.groupingBy { it }.eachCount().map { it.key to it.value }.toTypedArray() p.sortByDescending { it.first } var ans = 0 p.takeWhile { if (ans + it.second <= k) {ans+=it.second; true} else false } println(ans) }