Source Code
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define int ll


#define lp3(i,s,n) for(int i = s;i < int(n); ++i)
#define lp(i, n) lp3(i,0,n)
#define pb push_back
#define debug(x) cout<<"[" << #x << " is: " << x << "] "<<endl;

#define file freopen("input.in","r",stdin);
#define fastIO std::ios::sync_with_stdio(false); cin.tie(0);


void solve(){
    int n, m;
    cin>>n>>m;
    int mxH = 0;
    vector<int> b(n);
    lp(i, n){
        cin>>b[i];
        mxH = max(mxH, b[i]);
    }
    vector<int> h(mxH+1);
    lp(i, n){
        h[0]++;
        h[b[i]]--;
    }
    lp3(i, 1, mxH)
        h[i] += h[i-1];

    vector<bool> p(mxH+1, false);
    lp(i, m){
        int x, y;
        cin>>x>>y;
        p[y-1] = true;
    }

    int ans = 0;
    lp(i, mxH){
        if(!p[i])
            ans += h[i];
    }

    cout<<ans<<endl;
}

int32_t main() {  fastIO
    
    int t = 1; //cin>>t;
    while(t--){
        solve();
    }
    
    return 0;
}
Copy
Dr. Evil Logic
GNU G++17
37 ms
3.9 MB
Accepted