-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_1931.java
More file actions
63 lines (46 loc) Β· 1.5 KB
/
_1931.java
File metadata and controls
63 lines (46 loc) Β· 1.5 KB
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
package backjoon;
// https://www.acmicpc.net/problem/1931
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
public class _1931 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
/*
time[][0] μ μμμμ μ μλ―Έ
time[][1] μ μ’
λ£μμ μ μλ―Έ
*/
int[][] time = new int[N][2];
StringTokenizer st;
for(int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine(), " ");
time[i][0] = Integer.parseInt(st.nextToken()); // μμμκ°
time[i][1] = Integer.parseInt(st.nextToken()); // μ’
λ£μκ°
}
// λλλ μκ°μ κΈ°μ€μΌλ‘ μ λ ¬νκΈ° μν΄ compare μ¬μ μ
Arrays.sort(time, new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
// μ’
λ£μκ°μ΄ κ°μ κ²½μ° μμμκ° λΉ λ₯Έμ μ λ ¬
if(o1[1] == o2[1]) {
return o1[0] - o2[0];
}
return o1[1] - o2[1];
}
});
int count = 0;
int prev_end_time = 0;
for(int i = 0; i < N; i++) {
// μ§μ μ’
λ£μκ°μ΄ λ€μ νμ μμ μκ°λ³΄λ€ μκ±°λ κ°λ€λ©΄ κ°±μ
if(prev_end_time <= time[i][0]) {
prev_end_time = time[i][1];
count++;
}
}
System.out.println(count);
}
}