Skip to content

Commit

Permalink
solve(BOJ): G5_11000_강의실_배정_kt
Browse files Browse the repository at this point in the history
  • Loading branch information
gogumaC committed Jan 21, 2024
1 parent 7d34ce9 commit d62e24b
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/boj/G5_11000_강의실_배정.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package boj

import java.util.*

class BOJ11000() {
fun solve() {
val n = readln().toInt()
val lectures = Array(n) { IntArray(2) }

val finishTimes = PriorityQueue<Int>()
for (i in 0 until n) {
val (s, t) = readln().split(" ").map { it.toInt() }
lectures[i][0] = s
lectures[i][1] = t
}

lectures.sortWith { o1, o2 ->
if (o1[0] != o2[0]) o1[0] - o2[0] else o1[1] - o2[1]
}

for ((start, finish) in lectures) {

finishTimes.add(finish)
if (finishTimes.isEmpty()) continue
if (finishTimes.peek() <= start) {
finishTimes.remove()
}
}

println(finishTimes.size)


}
}

fun main() {
BOJ11000().solve()
}

0 comments on commit d62e24b

Please sign in to comment.