Source Code
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int N=2e5+9;


int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t,n,k,a[N];
    map<int,int>cnt;
    cin>>t;
    while(t--){
        cin>>n>>k;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        int i=0;
        bool all=true;
        while(k--){
            int x,y;
            cin>>x>>y;
            cnt.clear();
            bool ok=false;
            while(i<n){
                cnt[a[i]]++;
                if(cnt[x]==y){
                    ok=true;
                    break; 
                }
                i++;
            }
            if(!ok)all=false;
            else i++;
        }
        cout<<(all?"yes":"no")<<'\n';
    }
}
Copy
Sorted Array Partitioning Ahmed_Allawati
GNU G++17
93 ms
1.3 MB
Wrong Answer