fork download
  1. // Header File
  2. #include <bits/stdc++.h>
  3. using namespace std ;
  4.  
  5. // Speed
  6. #define Boost ios_base :: sync_with_stdio (0) ; cin.tie(0) ; cout.tie(0) ;
  7.  
  8. // DataTypes
  9. #define int long long
  10.  
  11. int memo[1010] ;
  12.  
  13. int rt ( vector <int> &h , vector <int> &iq , int i , int n , int x , int y ) {
  14. if ( i == n )
  15. return 0 ;
  16.  
  17. if ( memo[i] != -1 )
  18. return memo[i] ;
  19.  
  20. if ( h[i] > x and iq[i] < y ) {
  21. memo[i] = max ( rt(h,iq,i+1,n,x,y ) , 1 + rt(h,iq,i+1,n,h[i],iq[i] ) ) ;
  22. return memo[i] ;
  23. }
  24. return rt(h,iq,i+1,n,x,y ) ;
  25. }
  26.  
  27. void Go () {
  28. memset ( memo , -1 , sizeof(memo) ) ;
  29. int n = 0 ;
  30. cin >> n ;
  31.  
  32. vector <int> v(n,0) ;
  33. vector <int> t(n,0) ;
  34.  
  35. for ( int &i : v ) cin >> i ;
  36.  
  37. for ( int &i : t ) cin >> i ;
  38.  
  39. int max_sub = INT_MIN ;
  40. int curr = 0 ;
  41. for ( int i = 0 ; i < n ; i++ ) {
  42. int h = v[i] ;
  43. int iq = t[i] ;
  44. curr = 1+rt(v,t,i+1,n,h,iq) ;
  45. max_sub = max ( curr , max_sub ) ;
  46. }
  47. cout << max_sub << "\n" ;
  48. }
  49.  
  50. int32_t main () {
  51.  
  52. // #ifndef ONLINE_JUDGE
  53. // freopen("input.txt","r",stdin) ;
  54. // freopen("output.txt","w",stdout ) ;
  55. // #endif
  56.  
  57. Boost
  58.  
  59. // sieve() ;
  60.  
  61. int t = 1 ;
  62. cin >> t ;
  63. while ( t-- ) {
  64. Go() ;
  65. }
  66. }
  67.  
Success #stdin #stdout 0s 4812KB
stdin
2
3
1 2 3
3 2 1
4
1 3 2 4
5 6 4 4
stdout
3
2