Source Code
#include <bits/stdc++.h>
#define debug(a) cout << #a << ": " << a << "\n"
#define debugLine() cout << "==============\n"
#define tick() cout << "Tick\n";
#define testCases() int t; cin >> t; while(t--)
#define all(a) a.begin(), a.end()
#define fillWith(a, b) memset(a, b, sizeof(a))
#define INF_32 1e9
#define INF_64 1e18
#define Mod 1000000007
#define endl "\n"
#define goFast() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long ll;
using namespace std;

int main()
{
    goFast();
    testCases()
    {
        int n, k;
        cin >> n >> k;
        int arr[n + 3];
        vector<pair<int, int>> part;
        for(int i = 0; i < n; i++)
            cin >> arr[i];
        for(int i = 0; i < k; i++)
        {
            int x, y;
            cin >> x >> y;
            part.push_back({x, y});
        }
        int counter = 0;
        int partPTR = 0;
        for(int i = 0; i < n; i++)
        {
            if(counter == part[partPTR].second)
                partPTR++;
            else
            {
                if(arr[i] == part[partPTR].first)
                    counter++;
            }
        }
        if(partPTR != k)
            cout << "NO" << endl;
        else cout << "YES" << endl;
    }
}
Copy
Sorted Array Partitioning AhmadShahal
GNU G++17
90 ms
2.5 MB
Wrong Answer