fork download
  1.  
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. #define ll long long int
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(NULL);
  9. cout.tie(NULL);
  10. ll a,b;
  11. cin>>a>>b;
  12. ll arr[a];
  13. for(ll i=0;i<a;i++)
  14. {
  15. cin>>arr[i];
  16. }
  17. ll arr2[b];
  18. for(ll i=0;i<b;i++)
  19. {
  20. cin>>arr2[i];
  21. }
  22. ll i=0;
  23. ll j=0;
  24. while(i<a and j<b)
  25. {
  26. if(arr[i]==arr2[j])
  27. {
  28. i++;
  29. j++;
  30. }
  31. else
  32. {
  33. i++;
  34. }
  35. }
  36. if(j!=b)
  37. {
  38. cout<<"NO"<<endl;
  39. }
  40. else
  41. {
  42. cout<<"YES"<<endl;
  43. }
  44. }
Success #stdin #stdout 0.01s 5648KB
stdin
3 3
21 8 40
21 8 40

stdout
YES