//입력
3
1 3
2 4
3 5
//출력
2
import java.util.*;
// 백준 - 강의실 배정 - G5
class Dot implements Comparable<Dot> {
int st;
int et;
public Dot(int st, int et) {
this.st = st;
this.et = et;
}
@Override
public int compareTo(Dot o) {
if(this.st== o.st) return this.et - o.et;
return this.st - o.st;
}
}
public class ex11000 {
static int n;
static ArrayList<Dot> arr = new ArrayList<>();
static PriorityQueue<Integer> pq = new PriorityQueue<>();
public static int solution(){
Collections.sort(arr);
pq.offer(arr.get(0).et);
for(int i=1; i<n; i++){
if(pq.peek() <= arr.get(i).st) pq.poll();
pq.offer(arr.get(i).et);
}
return pq.size();
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
for(int i=0; i<n; i++){
int a = sc.nextInt();
int b = sc.nextInt();
arr.add(new Dot(a,b));
}
System.out.println(solution());
}
}
이 문제는 기본적으로 생각을 좀 하고 접근해야했다.
일단 문제에서 묻는 건 시간이 정해져있는 강의들을 하기 위해서 강의실을 몇개를 빌려야하는지 찾는 문제.