Source Code
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n, m, a[200000], freq[200001] = {};
	cin >> n >> m;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	for(int i = 0, x, y; i < m; ++i){
		cin >> x >> y;
		freq[y]++;
	}
	sort(a, a + n);
	int l = 0;
	long long ans = 0;
	for(int i = 1; i < 2e5 + 1; ++i){
		if(!freq[i]){
			while(a[l] < i && l < n){
				++l;
			}
			ans += n - l;
		}
	}
	cout << ans;
	return 0;
}
Copy
Dr. Evil azoz
GNU G++17
121 ms
2.3 MB
Accepted