반응형
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.PriorityQueue;
public class Main {
public static class Lecture implements Comparable<Lecture> {
long start;
long end;
public Lecture(int start, int end) {
this.start = start;
this.end = end;
}
@Override
public int compareTo(Lecture lec) {
return lec.start < start ? 1 : (lec.start > start ? -1 : 0);
}
}
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
PriorityQueue<Lecture> pq = new PriorityQueue<>();
for (int i = 0; i < n; i++) {
String[] s = br.readLine().split(" ");
pq.add(new Lecture(Integer.parseInt(s[1]), Integer.parseInt(s[2])));
}
PriorityQueue<Long> room = new PriorityQueue<>();
while (!pq.isEmpty()) {
Lecture lec = pq.poll();
if (room.isEmpty()) {
room.add(lec.end);
} else {
long r = room.poll();
if (lec.start < r)
room.add(r);
room.add(lec.end);
}
}
System.out.println(room.size());
}
}
반응형
'코딩 문제 풀이 > 백준' 카테고리의 다른 글
[백준] 자바 문제 풀이 16562 : 골드4 (0) | 2023.09.20 |
---|---|
[백준] 자바 문제 풀이 3190 : 골드4 (0) | 2023.09.19 |
[백준] 자바 문제 풀이 1043 : 골드4 (0) | 2023.09.19 |
[백준] 자바 문제 풀이 14891 : 골드5 (0) | 2023.09.19 |
[백준] 자바 문제 풀이 14503 : 골드5 (0) | 2023.09.19 |