Source Code
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define TEST int t;cin>>t;while(t--)
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fr first
#define sc second
#define popcount __builtin_popcountll
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const ll mod=1000000007;
typedef vector<int,int> p1;
typedef vector<ll,ll> p2;
int num[100010],nh[100010];
int main()
{
    IOS;
    //TEST{

  int n,m;
  cin>>n>>m;
  int h[100010],a,b;
  map<int,int>mm;
    for(int i=1;i<=n;i++)cin>>h[i];
    sort(h+1,h+1+n);
    int mx=0;
    rep(i,m){
        cin>>a>>b;
        mm[b]=1;
    mx=max(mx,b);
    }
int ans=0;
    int fl=1,j=0;
    for(int i=h[n];i> 0;i--){
           // cout<<i<<" "<<mm[i]<<" "<<j<<" "<<ans<<endl;

        if(i==h[n-j]){
            j++;
        }
    if(mm[i])continue;
        ans+=(j);
       // cout<<ans<<endl;
    }



 cout<<ans;
cout<<endl;
//}
    return 0;
}
Copy
Dr. Evil AlCoach
GNU G++17
34 ms
10.4 MB
Runtime Error