Source Code
#include <stdio.h>

int main(void) {
  long  n,m;
  scanf("%ld%ld",&n,&m);
  long  h[n], p[m][2];
  long  max_height = 0;
  for(int i = 0; i < n; i++){
    scanf("%ld ",&h[i]);
    if(h[i] > max_height) max_height = h[i];
  }
  for(int j = 0; j < m; j++){
    scanf("%ld%ld",&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 == 1) continue;
      for(int k = 0; k < n; k++){
        if(h[k] >= i) count ++;
        
      }
    
  }
  printf("%ld",count);
  
  
}
Copy
Dr. Evil Ayoooy
GNU G++17
1098 ms
5.5 MB
Time Limit Exceeded