-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_2565.java
More file actions
52 lines (43 loc) ยท 1.36 KB
/
_2565.java
File metadata and controls
52 lines (43 loc) ยท 1.36 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
package backjoon;
// https://www.acmicpc.net/problem/2565
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 _2565 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int[][] firstWire = new int[N][2];
int[] dp = new int[N];
StringTokenizer st;
for(int i = 0; i < firstWire.length; i++) {
st = new StringTokenizer(br.readLine()," ");
firstWire[i][0] = Integer.parseInt(st.nextToken());
firstWire[i][1] = Integer.parseInt(st.nextToken());
}
// ์ผ์ชฝ ์ ๋ด๋๋ฅผ ๊ธฐ์ค์ผ๋ก 2์ฐจ์ ๋ฐฐ์ด ์ ๋ ฌ
Arrays.sort(firstWire, new Comparator <int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
return o1[0] - o2[0];
}
});
for(int i=0; i<dp.length; i++){
dp[i] = 1;
for(int j=0; j<i; j++){
if(firstWire[i][1] > firstWire[j][1]){
dp[i] = Math.max(dp[i], dp[j]+1);
}
}
}
int max = 0;
for(int i=0; i<N; i++){
max = Math.max(max, dp[i]);
}
// ์ ์ฒด ์ ์ ๊ฐ์ - ์ต๋ ์ค์น๊ฐ๋ฅ ๊ฐ์ = ์ต์ ์ฒ ๊ฑฐ๊ฐ๋ฅ ๊ฐ์
System.out.println(N-max);
}
}