Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sprint3.tasks.I
- import java.io.BufferedReader
- import java.io.InputStreamReader
- import java.util.*
- fun main() {
- val reader = BufferedReader(InputStreamReader(System.`in`))
- val size = reader.readLine().toInt()
- val tokenizer = StringTokenizer(reader.readLine())
- List(size) { tokenizer.nextToken().toInt() }
- .run {
- associate { it to this.count { l -> l == it } }
- }
- .entries
- .sortedWith(compareBy({ -it.value }, { it.key }))
- .take(reader.readLine().toInt())
- .map { it.key }
- .joinToString(" ")
- .let(::println)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement