Skip to content

Commit 9512ff6

Browse files
authored
Merge pull request #1644 from AlgorithmWithGod/JHLEE325
[20251211] BOJ / G2 / 꼬인 전깃줄 / 이준희
2 parents 651a1ae + fe15378 commit 9512ff6

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
7+
public static void main(String[] args) throws Exception {
8+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
StringTokenizer st;
10+
11+
int N = Integer.parseInt(br.readLine());
12+
int[] arr = new int[N];
13+
14+
st = new StringTokenizer(br.readLine());
15+
for (int i = 0; i < N; i++) {
16+
arr[i] = Integer.parseInt(st.nextToken());
17+
}
18+
19+
int[] lis = new int[N];
20+
int len = 0;
21+
22+
for (int x : arr) {
23+
int pos = Arrays.binarySearch(lis, 0, len, x);
24+
if (pos < 0) pos = -(pos + 1);
25+
26+
lis[pos] = x;
27+
if (pos == len) len++;
28+
}
29+
30+
System.out.println(N - len);
31+
}
32+
}
33+
```

0 commit comments

Comments
 (0)