fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool checkSubset(vector<int>a , vector<int>b){
  5. unordered_map<int,int>mpp;
  6. for(int x:a){
  7. mpp[x]++;
  8. }
  9. for(int x:b){
  10. if(mpp.find(x)==mpp.end()){
  11. return false;
  12. }
  13. mpp[x]--;
  14. if(mpp[x]==0)mpp.erase(x);
  15. }
  16. return true;
  17. }
  18.  
  19. int main() {
  20. int n;
  21. cin>>n;
  22. vector<int>arr(n);
  23. for(int i=0;i<n;i++){
  24. cin>>arr[i];
  25. }
  26.  
  27. int m;
  28. cin>>m;
  29. vector<int>brr(m);
  30. for(int i=0;i<m;i++){
  31. cin>>brr[i];
  32. }
  33. if(checkSubset(arr,brr)){
  34. cout<<"Array2 is subset of Array1."<<endl;
  35. return 0;
  36. }
  37. else{
  38. cout<<"Not a subset.";
  39. }
  40. return 0;
  41. }
Success #stdin #stdout 0.01s 5272KB
stdin
5
1 3 6 5 8
3
1 1 5 8
stdout
Not a subset.