提交时间:2024-03-31 21:20:29
运行 ID: 140850
# include <bits/stdc++.h> using namespace std ; int f [10005] , a [10005] ; int main ( ) { int n = 1 , ans1 = 0 , ans2 = 0 ; while ( cin >> a [n] ) { n ++ ; } memset ( f , 1 , sizeof ( f ) ) ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= i ; j ++ ) { if ( a [i] < a [j] ) { f [i] = max ( f [i] , f [j] + 1 ) ; } } ans1 = max ( ans1 , f [i] ) ; } memset ( f , 1 , sizeof ( f ) ) ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= i ; j ++ ) { if ( a [i] > a [j] ) { f [i] = max ( f [i] , f [j] + 1 ) ; } } ans1 = max ( ans2 , f [i] ) ; } cout << ans1 << ' ' << ans2 << endl ; return 0 ; }