https://www.acmicpc.net/problem/1931
package javaTest;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class BOJ_1931 {
static Node[] Nodes;
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
Nodes = new Node[N];
int count = 0;
for(int i=0; i<N; i++) {
int s = sc.nextInt();
int e = sc.nextInt();
Nodes[i] = new Node(s, e);
}
Arrays.sort(Nodes, new Comparator<Node>() {
@Override
public int compare(Node o1, Node o2) {
if(o1.end == o2.end) {
return o1.start - o2.start;
}else {
return o1.end - o2.end;
}
}
});
int endTime = 0;
for(int i=0; i<N; i++) {
//System.out.println(Nodes[i].start + " " + Nodes[i].end);
//System.out.println(endTime);
if(endTime <= Nodes[i].start) {
endTime = Nodes[i].end;
count++;
}
}
System.out.println(count);
}
private static class Node{
int start;
int end;
public Node(int start, int end) {
this.start = start;
this.end = end;
}
}
}