import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
List<Times> list = new ArrayList<>();
StringTokenizer st;
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
long start = Long.parseLong(st.nextToken());
long end = Long.parseLong(st.nextToken());
list.add(new Times(start, end));
}
Collections.sort(list);
int result = 0;
long ends = -1;
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getStart() >= ends) {
ends = list.get(i).getEnd();
result++;
}
}
System.out.println(result);
}
private static class Times implements Comparable<Times> {
long start;
long end;
public long getStart() {
return start;
}
public long getEnd() {
return end;
}
public Times(long start, long end) {
this.start = start;
this.end = end;
}
@Override
public int compareTo(Times t) {
if (this.end == t.end) {
return this.start - t.start > 0 ? 1 : -1;
}
return this.end - t.end > 0 ? 1 : -1;
}
}
}
'Coding Test > 백준' 카테고리의 다른 글
[백준/자바] 1541 - 잃어버린 괄호 (0) | 2023.08.08 |
---|---|
[백준/자바] 1744 - 수 묶기 (0) | 2023.08.08 |
[백준/자바] 1715 - 카드 정렬하기 (0) | 2023.08.08 |
[백준/자바] 11047 - 동전 0 (0) | 2023.08.08 |
[백준/자바] 1300 - K번째 수 (0) | 2023.08.07 |