Ankit_132

C

Jun 3rd, 2024
899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5.     int t;
  6.     cin>>t;
  7.    
  8.     while(t--){
  9.         int n, m;
  10.         cin>>n;
  11.        
  12.         vector<int> a(n);
  13.         for(auto &e: a)
  14.             cin>>e;
  15.            
  16.         vector<int> b(n);
  17.         for(auto &e: b)
  18.             cin>>e;
  19.        
  20.         cin>>m;
  21.        
  22.         vector<int> d(m);
  23.         for(auto &e: d)
  24.             cin>>e;
  25.        
  26.         map<int, int> cnt1, cnt2;
  27.        
  28.         for(int i=0; i<n; i++){
  29.             if(a[i] != b[i])
  30.                 cnt1[b[i]]++;
  31.         }
  32.        
  33.         for(int j=0; j<m; j++)
  34.             cnt2[d[j]]++;
  35.            
  36.         int f = 1;
  37.            
  38.         for(auto [x, y]: cnt1){
  39.             if(cnt2[x] < y)
  40.                 f = 0;
  41.         }
  42.        
  43.         if(count(b.begin(), b.end(), d[m-1]) == 0)
  44.             f = 0;
  45.            
  46.         if(f)       cout<<"YES\n";
  47.         else        cout<<"NO\n";
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment