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 rt ( vector <int> h , vector <int> iq , int i , int n , int x , int y ) {
  12. if ( i == n )
  13. return 0 ;
  14.  
  15. if ( h[i] > x and iq[i] < y ) {
  16. return 1 + rt(h,iq,i+1,n,h[i],iq[i] ) ;
  17. }
  18. return rt(h,iq,i+1,n,x,y ) ;
  19. }
  20.  
  21. void Go () {
  22. int n = 0 ;
  23. cin >> n ;
  24.  
  25. vector <int> v(n,0) ;
  26. vector <int> t(n,0) ;
  27.  
  28. for ( int &i : v ) cin >> i ;
  29.  
  30. for ( int &i : t ) cin >> i ;
  31.  
  32. int max_sub = INT_MIN ;
  33. int curr = 0 ;
  34. for ( int i = 0 ; i < n ; i++ ) {
  35. int h = v[i] ;
  36. int iq = t[i] ;
  37. curr = 1+rt(v,t,i+1,n,h,iq) ;
  38. max_sub = max ( curr , max_sub ) ;
  39. }
  40. cout << max_sub << "\n" ;
  41. }
  42.  
  43. int32_t main () {
  44.  
  45. // #ifndef ONLINE_JUDGE
  46. // freopen("input.txt","r",stdin) ;
  47. // freopen("output.txt","w",stdout ) ;
  48. // #endif
  49.  
  50. Boost
  51.  
  52. // sieve() ;
  53.  
  54. int t = 1 ;
  55. cin >> t ;
  56. while ( t-- ) {
  57. Go() ;
  58. }
  59. }
  60.  
Success #stdin #stdout 0s 4680KB
stdin
2
3
1 2 3
3 2 1
4
1 3 2 4
5 6 4 4
stdout
3
2