링크 : https://www.acmicpc.net/problem/1966
소스코드 (Implement)
import java.io.BufferedReader
import java.io.FileInputStream
import java.io.InputStreamReader
import java.util.*
private var caseCount = 0
private fun main(){
val br = BufferedReader(InputStreamReader(System.`in`))
caseCount = br.readLine().toInt()
repeat(caseCount){
var count = 0
val Q : Queue<Point> = LinkedList()
val PQ = PriorityQueue<Point>()
val (N, M) = br.readLine().split(" ").map{ it.toInt() }
val weightList = br.readLine().split(" ").mapIndexed{ index, s -> Point(index, s.toInt()) }
Q.addAll(weightList)
PQ.addAll(weightList)
while (true){
val point = Q.poll()
val topValue = PQ.peek()
if (point.weight == topValue.weight){
PQ.remove()
count++
if (point.position == M){
println(count)
break
}
}else Q.add(point)
}
}
}
data class Point(
val position :Int,
val weight :Int
) :Comparable<Point> {
override fun compareTo(other: Point): Int =
other.weight -this.weight //내림 차순
}
'Algorithm_Kotlin' 카테고리의 다른 글
[Kotlin] BOJ2636 치즈 (0) | 2023.04.05 |
---|---|
[Kotlin] BOJ2116 주사위 쌓기 (0) | 2023.04.04 |
[Kotlin] BOJ1913 달팽이 (0) | 2023.03.09 |
[Kotlin] BOJ1063 킹 (1) | 2023.03.06 |
[Kotlin] BOJ14719 빗물 (0) | 2023.02.27 |