• + 0 comments
    def binarySearch(arr, low, high, key):
        while low <= high:
            mid = (low + high) // 2
            if arr[mid] < key:
                low = mid + 1
            else:
                high = mid - 1
        return low
    
    def longestIncreasingSubsequence(arr):
        n = len(arr)
        lis = [0] * n
        length = 0
    
        for i in range(n):
            pos = binarySearch(lis, 0, length - 1, arr[i])
            lis[pos] = arr[i]
            if pos == length:
                length += 1
    
        return length
    
    # Reading input
    n = int(input())
    arr = [int(input()) for _ in range(n)]
    
    # Finding and printing the length of the LIS
    result = longestIncreasingSubsequence(arr)
    print(result)