File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ package `4week`.acw
2
+
3
+
4
+ import java.util.PriorityQueue
5
+
6
+ class `acw회의실배정` {
7
+ val conferance = PriorityQueue <Pair <Int , Int >>(
8
+ Comparator { a, b ->
9
+ if (a.second - b.second == 0 ) {
10
+ a.first - b.first
11
+ } else {
12
+ a.second - b.second
13
+ }
14
+ }
15
+
16
+ )
17
+ // 종료시간이 빠른것을 기준으로 정렬한다.
18
+ // 종료시간이 같을 경우 시작시간이 더 빠른것을 위주로 정렬해야한다. -> 시작시간과 종료시간이 같은 회의가 있을 수 있기 때문
19
+ // ex) 5,6 / 6,6 이 있는데 6,6이 먼저 뽑힐 경우 56 /66이 모두 사용될 수 있음에도 불구하고 56은 선택되지 못한다.
20
+
21
+ fun solution () {
22
+ val N = readln().toInt()
23
+ var answer = 0
24
+ var lastConferance = Pair (0 , 0 )
25
+
26
+ repeat(N ) {
27
+ val (s, e) = readln().split(" " ).map { it.toInt() }
28
+ conferance.add(Pair (s, e))
29
+
30
+ }
31
+ lastConferance = conferance.poll()
32
+ answer++
33
+
34
+
35
+ while (conferance.isNotEmpty()) {
36
+ val nowConferance = conferance.poll()
37
+ if (nowConferance.first < lastConferance.second) {
38
+ continue
39
+ } else {
40
+ lastConferance = nowConferance
41
+ answer++
42
+ }
43
+
44
+ }
45
+ println (answer)
46
+
47
+
48
+ }
49
+
50
+ }
51
+
52
+ fun main () {
53
+ val sol = `acw회의실배정`()
54
+ sol.solution()
55
+ }
You can’t perform that action at this time.
0 commit comments