• + 0 comments
    //package solve_problems;
    /*
     * 2024 ^_^
     *ThinhNguyen97
     * 
     */
    
    import java.math.BigInteger;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.HashMap;
    import java.util.Set;
    import java.util.HashSet;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.Map;
    import java.util.Queue;
    import java.util.Scanner;
    import java.util.Stack;
    
    
    
    public class Solve_problems 
    {
       static void solve(int n, int[] array) 
       {
           List<Integer> res=new ArrayList<>();
           res.add(array[0]);
           for (int i = 1; i < n; i++) 
           {
                int pos = Collections.binarySearch(res, array[i]);
    
                if (pos < 0) {
                    // Element not found, calculate the insertion point
                    pos = -pos - 1;
                    if (pos == res.size())
                        res.add(array[i]);
                    else
                        res.set(pos, array[i]);
                }
               // Print the current LIS
    //           res.forEach((x) -> {
    //               System.out.print(x + " ");
    //           });
    //            System.out.println();
            }
           // Print the length of the LIS
            System.out.println(res.size());
        }
    
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
    
            // Input
            int n = sc.nextInt();
            int[] array = new int[n];
            for (int i = 0; i < n; i++)
                array[i] = sc.nextInt();
    
            // Solve the problem
            solve(n, array);
    
            // Close the Scanner instance
            sc.close();
        }
    }