-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLISTestBS.java
More file actions
46 lines (39 loc) · 729 Bytes
/
LISTestBS.java
File metadata and controls
46 lines (39 loc) · 729 Bytes
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
package algorithm;
import java.util.*;
public class LISTestBS {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] C = new int[N+1];
int[] prev = new int[N+1];
Arrays.fill(C, Integer.MAX_VALUE);
C[0] = 0;
int max = 0;
for (int i = 0; i < N; i++) {
int num = sc.nextInt();
int p = ~Arrays.binarySearch(C, num);
C[p] = num;
if (max < p) {
max = p;
prev[p-1] = C[p-1];
prev[p] = num;
}
}
// prev[max] = C[max];
for (int i = 1; i <= max; i++)
System.out.print(prev[i]+" ");
System.out.println();
System.out.println(max);
sc.close();
}
}
/*
6
3 2 6 4 5 1
==>3
10
8 2 4 3 6 11 7 10 14 5
==>6
8
2 5 4 7 6 8 1 3
*/