Source Code
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define IN freopen("input.txt", "r", stdin)
#define OUT freopen("output.txt", "w", stdout)
typedef vector<int> vi;
typedef pair<int, int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i <= b; i++)
void dfs(string a, string b, int si)
{
}
int main()
{
    int tt;
    cin >> tt;
    while (tt--)
    {
        int n, k;
        cin >> n >> k;
        int arr[n];
        int frq[100009] = {};
        for (int i = 0; i < n; i++)
            cin >> arr[i], frq[arr[i]]++;
        bool f = 1;
        for (int i = 0; i < k; i++)
        {
            int x, y;
            cin >> x >> y;
            while (arr[i] == arr[i + 1])
                i++;
            if (x != arr[i] || y > frq[arr[i]])
                f = 0;
        }
        if (f)
            cout << "YES\n";
        else
            cout << "NO\n";
    }
}
Copy
Sorted Array Partitioning monther abu zaina
GNU G++17
4 ms
776 KB
Wrong Answer