Skip to content

Commit 22c9843

Browse files
authored
[20251019] BOJ / G5 / 전깃줄 / 강신지
1 parent b7624dd commit 22c9843

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

ksinji/202510/19 BOJ 전깃줄.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
static class Wire implements Comparable<Wire> {
7+
int a, b;
8+
Wire(int a, int b) {
9+
this.a = a;
10+
this.b = b;
11+
}
12+
13+
@Override
14+
public int compareTo(Wire o) {
15+
return this.a - o.a;
16+
}
17+
}
18+
19+
public static void main(String[] args) throws Exception {
20+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
21+
int N = Integer.parseInt(br.readLine());
22+
23+
Wire[] arr = new Wire[N];
24+
int[] dp = new int[N];
25+
for (int i = 0; i < N; i++) {
26+
StringTokenizer st = new StringTokenizer(br.readLine());
27+
int a = Integer.parseInt(st.nextToken());
28+
int b = Integer.parseInt(st.nextToken());
29+
arr[i] = new Wire(a, b);
30+
}
31+
32+
Arrays.sort(arr);
33+
34+
int max = 1;
35+
for (int i = 0; i < N; i++) {
36+
dp[i] = 1;
37+
for (int j = 0; j < i; j++) {
38+
if (arr[i].b > arr[j].b) {
39+
dp[i] = Math.max(dp[i], dp[j] + 1);
40+
}
41+
}
42+
max = Math.max(max, dp[i]);
43+
}
44+
```
45+
System.out.println(N - max);
46+
}
47+
}

0 commit comments

Comments
 (0)