IMohammedNasr

Untitled

Dec 9th, 2021
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. void ez()
  6. {
  7. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  8. #ifndef ONLINE_JUDGE
  9. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  10. #endif
  11. }
  12.  
  13. bool comp(ll &a, ll &b)
  14. {
  15. return a > b;
  16. }
  17.  
  18. void solve()
  19. {
  20. ll n, m, ans = 0;
  21. cin >> n >> m;
  22. vector<ll> a(n), b(m), h;
  23. for (auto &i : a)
  24. cin >> i;
  25. for (auto &i : b)
  26. cin >> i;
  27. ll f = 0, l = 0;
  28.  
  29. while (f < n and l < m)
  30. {
  31. ll cnt = 0;
  32. while (l < m and b[l] < a[f])
  33. {
  34. l++;
  35. }
  36. while (a[f] == b[l])
  37. {
  38. cnt++;
  39. l++;
  40. }
  41.  
  42. do
  43. {
  44. f++;
  45. ans += cnt;
  46. } while (a[f] == a[f - 1]);
  47. }
  48.  
  49. cout << ans << endl;
  50. }
  51.  
  52. int main()
  53. {
  54. ez();
  55. int t = 1;
  56. // cin >> t;
  57. while (t--)
  58. solve();
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment