Skip to content

Commit ed1ee19

Browse files
Merge pull request #1657 from AlgorithmWithGod/Seol-JY
2 parents 918634d + 3bfe7f2 commit ed1ee19

File tree

1 file changed

+31
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)