File tree Expand file tree Collapse file tree 1 file changed +67
-0
lines changed
Expand file tree Collapse file tree 1 file changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ ```
2+ import java.io.*;
3+ import java.util.StringTokenizer;
4+
5+ public class Main {
6+ private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+ private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+ private static int[] arr, lis;
9+ private static int N;
10+
11+ public static void main(String[] args) throws IOException {
12+ init();
13+ int answer = DP();
14+
15+ bw.write(answer + "\n");
16+ bw.flush();
17+ bw.close();
18+ br.close();
19+ }
20+
21+ private static void init() throws IOException {
22+ N = Integer.parseInt(br.readLine());
23+
24+ StringTokenizer st = new StringTokenizer(br.readLine());
25+ arr = new int[N];
26+ lis = new int[N];
27+
28+ for (int i = 0; i < N; i++) {
29+ arr[i] = Integer.parseInt(st.nextToken());
30+ }
31+ }
32+
33+ private static int DP() {
34+ int len = 0;
35+
36+ for (int i = 0; i < N; i++) {
37+ int key = arr[i];
38+
39+ if (len == 0 || lis[len-1] < key) {
40+ lis[len] = key;
41+ len++;
42+ } else {
43+ int index = binarySearch(len-1, key);
44+ lis[index] = key;
45+ }
46+ }
47+
48+ return len;
49+ }
50+
51+ private static int binarySearch(int right, int key) {
52+ int left = 0;
53+
54+ while (left < right) {
55+ int mid = left + (right-left)/2;
56+
57+ if (lis[mid] >= key) {
58+ right = mid;
59+ } else {
60+ left = mid+1;
61+ }
62+ }
63+
64+ return right;
65+ }
66+ }
67+ ```
You can’t perform that action at this time.
0 commit comments