提交时间:2024-03-31 20:59:47
运行 ID: 140847
# include <bits/stdc++.h> using namespace std ; int a [5005] = { 114514 } , g [5005] , Lis [100001] ; int main ( ) { int n = 1 , maxn = -1 , m = 0 , lgg = 0 ; while ( cin >> a [n] ) { n ++ ; } for ( int i = 1 ; i <= n ; i ++ ) { if ( ! ( i - 1 ) ) { Lis [lgg ++] = a [i] ; } else { if ( a [i] < Lis [lgg - 1] ) { int j = upper_bound ( Lis , Lis + lgg , a [i] ) - Lis ; Lis [j] = a [i] ; } else { Lis [lgg ++] = a [i] ; } } } for ( int i = 1 ; i <= n ; i ++ ) { int k = 1 ; while ( k <= m && g [k] < a [i] ) { k ++ ; } if ( k > m ) { g [++ m] = a [i] ; } else { g [k] = a [i] ; } } cout << lgg << ' ' << m << endl ; return 0 ; }