https://www.acmicpc.net/problem/11000
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.PriorityQueue;
public class Main {
public int getClassroomNum(Class[] class_list) {
Arrays.sort(class_list);
PriorityQueue<Integer> pqueue = new PriorityQueue<>();
pqueue.offer(class_list[0].end);
for(int i = 1; i < class_list.length; i++) {
if(pqueue.peek() <= class_list[i].start) {
pqueue.poll();
}
pqueue.offer(class_list[i].end);
}
return pqueue.size();
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int num = Integer.parseInt(br.readLine());
Class[] class_list = new Class[num];
for(int i = 0; i < num; i++) {
String[] input = br.readLine().split(" ");
class_list[i] = new Class(Integer.parseInt(input[0]), Integer.parseInt(input[1]));
}
br.close();
Main m = new Main();
bw.write(m.getClassroomNum(class_list) + "\n");
bw.flush();
bw.close();
}
public static class Class implements Comparable<Class> {
int start, end;
public Class(int start, int end) {
this.start = start;
this.end = end;
}
@Override
public int compareTo(Class c) {
// TODO Auto-generated method stub
if(this.start < c.start) {
return -1;
} else if(this.start > c.start) {
return 1;
} else {
if(this.end < c.end) {
return -1;
} else if(this.end > c.end) {
return 1;
} else {
return 0;
}
}
}
}
}