Source Code
#include <bits/stdc++.h>

#define FIO ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef long double ld;

using namespace std;

const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const ll INF = 1e18;

int main()
{
    FIO
    int n, m, a, b, ans = 0;
    bool f[N] = {};
    cin >> n >> m;
    vector<int> h(n);
    for (int i = 0; i < n; i++)
        cin >> h[i];
    for (int i = 0; i < m; i++)
    {
        cin >> a >> b;
        f[b] = true;
    }
    sort(h.begin(), h.end());
    for (int i = 1; i <= h[n - 1]; i++)
    {
        if (!f[i])
            ans += n - (lower_bound(h.begin(), h.end(), i) - h.begin());
    }
    cout << ans << '\n';
    return 0;
}
Copy
Dr. Evil Mariam_Yasser
GNU G++17
52 ms
1.6 MB
Wrong Answer