fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include<string>
  4. #include <algorithm>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8. #define all(v) (v.begin()),(v.end())
  9.  
  10. int main() {
  11. int n, m;
  12. cin >> n >> m;
  13. vector<int> arrN;
  14. vector<int> arrM;
  15.  
  16. int temp = 0;
  17. while (temp < n){
  18. int x;
  19. cin >> x;
  20. arrN.push_back(x);
  21. temp++;
  22. }
  23. temp = 0;
  24. while (temp < m){
  25. int x;
  26. cin >> x;
  27. arrM.push_back(x);
  28. temp++;
  29. }
  30.  
  31. for (int i = 0; i < arrN.size(); i++){
  32. int e = arrN[i];
  33. auto it = find(all(arrM), e);
  34. if (it == arrM.end()){
  35. arrN.erase(arrN.begin() + i);
  36. }
  37. }
  38. int count = 0;
  39. for (int i = 0; i < arrN.size(); i++){
  40. if (arrN[i] == arrM[i]){
  41. count++;
  42. }
  43. }
  44. if (count == arrN.size()){
  45. cout << "YES";
  46. }else{
  47. cout << "NO";
  48. }
  49. return 0;
  50. }
Success #stdin #stdout 0.01s 5284KB
stdin
3 2
1 4 7
1 7
stdout
YES