fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std ;
  4. const int MABU=1e6;
  5. vector<ll>a(MABU);
  6. vector<ll>b(MABU);
  7. int main()
  8. {
  9. ios_base::sync_with_stdio(false);
  10. cin.tie(0);
  11. cout.tie(0);
  12. freopen("MARBLE.INP","r",stdin);
  13. freopen("MARBLE.OUT","w",stdout);
  14. ll n;
  15. cin>>n;
  16. for(ll i = 0; i< n ;i++)
  17. {
  18. cin>>a[i];
  19. }
  20. ll m ;
  21. cin>>m;
  22. for(ll i = 0 ; i<m;i++)
  23. {
  24. cin>>b[i];
  25. }
  26. vector<ll>d;
  27. for(ll i = m -2 ;i>=0;i--)
  28. {
  29. if(b[i]>b[i+1])
  30. {
  31. for(ll j = i+1 ; j<=m;j++)
  32. {
  33. d.push_back(b[j]);
  34. }
  35. break;
  36. }
  37. }
  38. ll res = 1 ;
  39. for(ll i = 0;i<n;i++)
  40. {
  41. ll pos = lower_bound(d.begin(),d.end(),a[i])-d.begin();
  42. if(a[i]>a[i+1])
  43. break;
  44. if(pos!=d.size())
  45. res=max(res,((i+1)+(m-(pos+1))));
  46. else
  47. break;
  48.  
  49. }
  50. cout<<res<<endl;
  51. return 0;
  52. }
  53. //3
  54. //1 4 9
  55. //4
  56. //5 2 4 5
  57.  
Success #stdin #stdout 0.01s 18728KB
stdin
Standard input is empty
stdout
Standard output is empty