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

int t,n,k,a[N];
vector<pair<int,int>>v;
vector<int>b;
map<int,int>cnt;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>t;
    while(t--){
        v.clear();
        b.clear();
        cin>>n>>k;
        for(int i=0;i<n;i++){
            cin>>a[i];
            cnt[a[i]]++;
        }
        for(int i=0;i<k;i++){
            int x,y;
            cin>>x>>y;
            b.push_back(x);
            v.push_back({x,y});
        }
        if(!is_sorted(b.begin(),b.end())){
            cout<<"no"<<'\n';
            continue;
        }
        bool all=true;
        for(int i=0;i<k;i++){
            if(cnt[v[i].first]<v[i].second)all=false;
        }
        cout<<(all?"yes":"no")<<'\n';
    }
}
Copy
Sorted Array Partitioning Ahmed_Allawati
GNU G++17
100 ms
2.4 MB
Wrong Answer