티스토리 뷰
https://www.acmicpc.net/problem/1931
코드
import java.io.*;
import java.util.*;
public class Main {
static int N;
static List<Meeting> meetings = new ArrayList<>();
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
StringTokenizer st;
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
meetings.add(new Meeting(a, b));
}
Collections.sort(meetings);
int cnt = 0;
int startTime = 0;
for (Meeting meeting : meetings) {
if (startTime <= meeting.start) {
cnt++;
startTime = meeting.end;
}
}
System.out.println(cnt);
}
static class Meeting implements Comparable<Meeting> {
int start, end;
public Meeting(int start, int end) {
this.start = start;
this.end = end;
}
@Override
public int compareTo(Meeting other) {
if (this.end == other.end) {
return this.start - other.start;
}
return this.end - other.end;
}
}
}