/
Main.java
64 lines (53 loc) · 1.29 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* @author Minha Gwon
* @date 2021. 1. 23.
* 회의실 배정
* https://www.acmicpc.net/problem/1931
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
class Time implements Comparable<Time> {
int start;
int end;
Time(int start, int end) {
this.start = start;
this.end = end;
}
@Override
public int compareTo(Time t) {
if (this.end > t.end) { // 끝나는 시간 기준 오름차순 정렬
return 1;
} else if (this.end == t.end) {
if(this.start > t.start) { // 끝나는 시간 같다면 시작 시간 기준 오름차순
return 1;
} else {
return -1;
}
} else {
return -1;
}
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
ArrayList<Time> timeList = new ArrayList<>();
for(int i = 0; i < N; i++) {
int a = sc.nextInt();
int b = sc.nextInt();
timeList.add(new Time(a, b));
}
Collections.sort(timeList);
int ans = 1;
int endTime = timeList.get(0).end;
for(int i = 1; i < timeList.size(); i++) {
if(timeList.get(i).start >= endTime) {
endTime = timeList.get(i).end;
ans++;
}
}
System.out.println(ans);
}
}