fork download
  1. //#pragma GCC optimize("O3", "unroll-loops")
  2. //#pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt")
  3.  
  4. #include <bits/stdc++.h>
  5. #include <iterator>
  6. #define ldb long double
  7. //#define double ldb
  8. #define db double
  9. #define unomap unordered_map
  10. #define unoset unordered_set
  11. #define endl '\n'
  12. #define str string
  13. #define strstr stringstream
  14. #define sz(a) (int)a.size()
  15. #define ll long long
  16. //#define int ll
  17. #define pii pair <int, int>
  18. #define pll pair <ll, ll>
  19. #define Unique(a) a.resize(unique(all(a)) - a.begin())
  20. #define ull unsigned ll
  21. #define fir first
  22. #define sec second
  23. #define idc cin.ignore()
  24. #define lb lower_bound
  25. #define ub upper_bound
  26. #define all(s) s.begin(), s.end()
  27. #define rev reverse
  28. #define gcd __gcd
  29. #define pushb push_back
  30. #define popb pop_back
  31. #define pushf push_front
  32. #define popf pop_front
  33. #define mul2x(a, x) a << x
  34. #define div2x(a, x) a >> x
  35. #define lcm(a, b) (a / __gcd(a, b) * b)
  36. #define log_base(x, base) log(x) / log(base)
  37. #define debug cerr << "No errors!"; exit(0);
  38. #define forw(i, a, b) for (int i = a; i <= b; ++i)
  39. #define forw2(i, a, b) for (ll i = a; i <= b; ++i)
  40. #define fors(i, a, b) for (int i = a; i >= b; --i)
  41. #define fors2(i, a, b) for (ll i = a; i >= b; --i)
  42. #define pqueue priority_queue
  43. #define sqrt sqrtl
  44. #define i128 __int128
  45. #define popcount __builtin_popcountll
  46. #define BIT(x, i) (((x) >> (i)) & 1)
  47. #define MASK(x) ((1LL) << (x))
  48. #define want_digit(x) cout << fixed << setprecision(x);
  49. #define excuting_time 1000.0 * clock() / CLOCKS_PER_SEC
  50. #define mapa make_pair
  51. using namespace std;
  52. const int MOD = 1e9 + 7; // 998244353
  53. const int inf = 1e9;
  54. const ll INF = 1e18;
  55. const int N = 1e3;
  56.  
  57. mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  58. ll random(const ll &L, const ll &R) {
  59. return uniform_int_distribution<ll> (L, R) (rng);
  60. }
  61.  
  62. int n, m, a[N + 5], b[N + 5], pre[N + 5], suf[N + 5];
  63. void solve() {
  64. cin >> n >> m;
  65. forw (i, 1, n) cin >> a[i];
  66. forw (i, 1, m) cin >> b[i];
  67.  
  68. forw (i, 1, n) {
  69. pre[i] = 1;
  70. if (a[i - 1] <= a[i]) pre[i] += pre[i - 1];
  71. }
  72.  
  73. fors (i, m, 1) {
  74. suf[i] = 1;
  75. if (b[i] <= b[i + 1]) suf[i] += suf[i + 1];
  76. }
  77.  
  78. int ans = 0;
  79. forw (i, 1, n) {
  80. forw (j, 1, m) {
  81. if (a[i] <= b[j]) {
  82. if (pre[i] == 1 || suf[i] == 1) continue;
  83. ans = max(ans, pre[i] + suf[j]);
  84. }
  85. }
  86. }
  87. cout << ans << endl;
  88. }
  89.  
  90. signed main() {
  91. ios::sync_with_stdio(false), cin.tie(nullptr);
  92. srand(time(NULL));
  93. #define name "test"
  94. /*
  95.   if (fopen(name".INP", "r")) {
  96.   freopen(name".INP", "r", stdin);
  97.   freopen(name".OUT", "w", stdout);
  98.   }
  99.   */
  100. bool testCase = false;
  101. int numTest = 1;
  102. // cin >> numTest;
  103. forw (i, 1, numTest) {
  104. if (testCase) cout << "Case " << i << ": ";
  105. solve();
  106. }
  107. return 0;
  108. }
  109.  
  110. /*
  111.   /\__/\
  112.  (=^.^= )
  113.  (") (")_/
  114. */
  115.  
Success #stdin #stdout 0.01s 5328KB
stdin
Standard input is empty
stdout
0