반응형
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
static int[][] conference;
static int N;
static int K;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
conference = new int[N][2];
for (int i = 0; i < N; i++) {
for (int j = 0; j < 2; j++) {
conference[i][j] = sc.nextInt();
}
}
Arrays.sort(conference, new Comparator<int[]>() {
@Override
public int compare(int[] arr1, int[] arr2) {
if (arr1[1] == arr2[1]) {
return arr1[0] - arr2[0];
} else {
return arr1[1] - arr2[1];
}
}
});
int end = 0;
int result = 0;
for (int i = 0; i < N; i++) {
if (conference[i][0] >= end) {
end = conference[i][1];
result++;
}
}
System.out.println(result);
}
}
반응형
LIST
'알고리즘 > 연습문제' 카테고리의 다른 글
백준 - 2217 로프 (feat. java) (0) | 2019.08.13 |
---|---|
백준 - 5585 거스름돈 (feat. java) (0) | 2019.08.13 |
백준 - 11047 동전 0 (feat. java) (0) | 2019.08.13 |
백준 - 11399 ATM(feat. java) (0) | 2019.08.13 |
백준 - 7576 토마토(feat. java) (0) | 2019.08.12 |