이 문제는 끝나는 시간 기준으로 오름차순 정렬을 했고 만약 끝나는 시간이 같다면 시작 시간을 기준으로 오름차순을 수행했다.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
class Node implements Comparable<Node>{
int start;
int end;
public Node(int start, int end){
this.start = start;
this.end = end;
}
public int compareTo(Node o){
if(this.end == o.end){
return this.start - o.start;
}
return this.end - o.end;
}
}
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int testCase = Integer.parseInt(br.readLine());
Queue<Node> pq = new PriorityQueue<>();
for(int t=0;t<testCase;t++){
String[] arr = br.readLine().split(" ");
pq.add(new Node(Integer.parseInt(arr[0]), Integer.parseInt(arr[1])));
}
int time = 0;
int count = 0;
while(!pq.isEmpty()){
Node element = pq.poll();
if(element.start >= time){
time = element.end;
count++;
}
}
System.out.println(count);
}
}