Source Code
#include "bits/stdc++.h"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;

void solve(){
    int n,k;
    cin>>n>>k;
    map<int,int> m;
    for (int i = 0; i < n; ++i)
    {
        int v;
        cin>>v;
        m[v]++;
    }
    vector<pair<int,int>> p(k);
    for (int i = 0; i < k; ++i)
    {
        cin>>p[i].first>>p[i].second;
    }
    if(p[0].second > m[p[0].first]){
            cout<<"no\n";
            return;
        }
    for (int i = 1; i < k; ++i)
    {
        if(p[i].first < p[i-1].first){
            cout<<"no\n";
            return;
        }
        if(p[i].second > m[p[i].first]){
            cout<<"no\n";
            return;
        }
    }
    cout<<"yes\n";
}

int main(){
    #ifndef ONLINE_JUDGE
     freopen("input.txt", "r", stdin);
     freopen("out.txt", "w",stdout);
    #endif
    FAST;

    int t = 1;
    cin>>t;
    while(t--)
        solve();    
}
Copy
Sorted Array Partitioning moathhamudah
GNU G++17
121 ms
1.9 MB
Wrong Answer