https://www.acmicpc.net/problem/12015
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int N;
static int[] A;
static void input() {
Reader scanner = new Reader();
N = scanner.nextInt();
A = new int[N];
for(int idx = 0; idx < N; idx++)
A[idx] = scanner.nextInt();
}
static void solution() {
int[] LIS = new int[N];
LIS[0] = A[0];
int len = 1;
for(int idx = 1; idx < N; idx++) {
int key = A[idx];
if(LIS[len - 1] < key) {
len++;
LIS[len - 1] = key;
} else {
int min = 0, max = len;
while(min < max) {
int mid = (min + max) / 2;
if(LIS[mid] < key) {
min = mid + 1;
} else {
max = mid;
}
}
LIS[min] = key;
}
}
System.out.println(len);
}
public static void main(String[] args) {
input();
solution();
}
static class Reader {
BufferedReader br;
StringTokenizer st;
public Reader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while(st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
}
}