-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJava_12738.java
More file actions
38 lines (36 loc) · 1.18 KB
/
Java_12738.java
File metadata and controls
38 lines (36 loc) · 1.18 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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Java_12738 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int[] arr = new int[N];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
int[] increases = new int[N];
int lastIdx=0;
increases[0]=arr[0];
for (int a : arr) {
if (a > increases[lastIdx]) {
increases[++lastIdx]=a;
}
else {
int left = 0, right =lastIdx,idx=0;
while (left<=right){
int mid = (left+right)/2;
if(a>increases[mid])
left=mid+1;
else {
right=mid-1;
idx=mid;
}
}
increases[idx]=a;
}
}
System.out.println(lastIdx+1);
}
}