diff --git "a/zinnnn37/202601/28 BOJ G2 \352\260\200\354\236\245 \352\270\264 \354\246\235\352\260\200\355\225\230\353\212\224 \353\266\200\353\266\204 \354\210\230\354\227\264 3.md" "b/zinnnn37/202601/28 BOJ G2 \352\260\200\354\236\245 \352\270\264 \354\246\235\352\260\200\355\225\230\353\212\224 \353\266\200\353\266\204 \354\210\230\354\227\264 3.md" new file mode 100644 index 00000000..b2991f19 --- /dev/null +++ "b/zinnnn37/202601/28 BOJ G2 \352\260\200\354\236\245 \352\270\264 \354\246\235\352\260\200\355\225\230\353\212\224 \353\266\200\353\266\204 \354\210\230\354\227\264 3.md" @@ -0,0 +1,66 @@ +```java +import java.io.*; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +public class BJ_12738_가장_긴_증가하는_부분_수열_3 { + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static StringTokenizer st; + + private static int N; + private static int[] arr; + private static List list; + + public static void main(String[] args) throws IOException { + init(); + sol(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + + arr = new int[N]; + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + } + list = new ArrayList<>(); + } + + private static void sol() throws IOException { + list.add(Integer.MIN_VALUE); + + for (int a : arr) { + int size = list.size() - 1; + + if (list.get(size) < a) { + list.add(a); + } else { + int index = binarySearch(0, size, a); + + list.set(index, a); + } + } + bw.write(list.size() - 1 + ""); + bw.flush(); + bw.close(); + br.close(); + } + + private static int binarySearch(int left, int right, int target) { + while (left < right) { + int mid = left + (right - left) / 2; + if (list.get(mid) < target) { + left = mid + 1; + } else { + right = mid; + } + } + return right; + } + +} +````