Source Code
#include <bits/stdc++.h>
using namespace std;
const int N = 1000001; 

int a[N] ; 
int main() {
	int t ; 
	scanf("%d" , &t) ; 
	while (t--) {
		int n , k ; 
		scanf("%d%d" , &n , &k) ; 
		for(int i = 0 ; i<n ; ++i)
			scanf("%d" , &a[i]) ; 
		
		vector<pair<int , int>>p ;  
		int x,  y; 
		scanf("%d%d" , &x , &y) ; 
		p.push_back(make_pair(x, y)) ; 
		for(int i = 1 ; i<k ; ++i) {
			scanf("%d%d" , &x , &y) ;
			if (x == p.back().first)
				p.back().second+=y;
			else 
				p.push_back(make_pair(x, y)) ; 
		}
		map<int, int>mp ; 
		int j = 0 ; 
		for (int i = 0 ; i<n ; ++i) {
			int x = p[j].first; 
			int y = p[j].second ; 
			mp[a[i]]++;
			if (mp[x] == y){
				j++;
				mp.clear();
			}
			
			if (j == p.size())
				break;
		}
	//	cout<<j<<endl;
		if (j == p.size() )
			puts("yes");
		else 
			puts("no") ; 
			
	}
	return 0;
}
Copy
Sorted Array Partitioning Chicou
GNU G++17
99 ms
1.1 MB
Wrong Answer