Source Code
#include <stdio.h>

int main(void) {
  long long n,m;
  scanf("%lld%lld",&n,&m);
  long long h[n], p[m][2];
  long long max_height = 0;
  for(int i = 0; i < n; i++){
    scanf("%lld ",&h[i]);
    if(h[i] > max_height) max_height = h[i];
  }
  for(int j = 0; j < m; j++){
    scanf("%lld%lld",&p[j][0],&p[j][1]);
  }
  long count = 0,flag = 0;
  for(int i = 1; i <= max_height; i++){
    flag = 0;
    for(int j = 0; j < m; j++){
      if(p[j][1] == i){
        flag = 1;
        break;
      }
    }
    if(flag == 0){
      for(int k = 0; k < n; k++){
        if(h[k] >= i){
          count ++;
        }
      }
      
    }
    
    
  }
  printf("%ld",count);
  
  
}
Copy
Dr. Evil Ayoooy
GNU G++17
1044 ms
5.6 MB
Time Limit Exceeded