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

#define IO  ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define endl '\n'
#define f first
#define s second
#define ll long long
#define ld long double
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f

using namespace std;
const int M = 2e5 + 5, C = 1e5 + 5;

bool mp[M];
int arr[M];
int main() {
    IO
    int n,m;
    cin>>n>>m;
    vector<int>v(n);
    int x,y;
    for(auto &i:v) cin>>i,arr[i]++;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        mp[y]=1;
    }
    sort(v.rbegin(),v.rend());
    ll ans=0;
    for(int i=v[0]-1;i>0;i--){
        arr[i]+=arr[i+1];
    }
    for(int i=v[0];i>0;i--){
        if(mp[i]) continue;
        ans+=arr[i];
    }
    cout<<ans;
    return 0;
}
Copy
Dr. Evil Sarah_Montasser
GNU G++17
52 ms
2.5 MB
Accepted