Problem p02689 (C++) — buggy submission, verdict: Runtime Error

/*#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {

        ll n,total = 0;
        cin>>n;
        ll arr[n+1];
        multiset <ll> str;
        multiset <ll> :: iterator itr1, itr2;
        for(ll i=1; i<=n; i++) {
                cin>>arr[i];
                str.insert(arr[i] + i);
        }
        for(ll i=1; i<=n; i++) {
                ll c = i - arr[i];
                if(c>0) {
                itr1 = str.lower_bound(c);
                itr2 = str.upper_bound(c);
                //cout<<*itr1<<" "<<*itr2<<"\\n";
                total += distance(itr1,itr2);
                }
        }

        cout<<total;
        for(itr1 = str.begin(); itr1!= str.end(); itr1++){
                cout<<*itr1<<" ";
        }

        cout<<distance(itr1,itr2);

        //return 0;
}*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<vector<pair<int, int>>> adj;
int main() {
  int n, m;
  cin >> n >> m;
  adj.resize(n + 1);
  // cout<<n<<m;
  int h[n + 1];
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  int a, b;
  for (int j = 0; j < m; j++) {
    cin >> a >> b;
    adj[a].push_back(make_pair(b, h[a]));
    adj[b].push_back(make_pair(a, h[b]));
  }

  int oop = 0, total = 0;
  // vector<bool> check(n+1 , false);
  for (int i = 1; i <= n; i++) {
    oop = 0;
    if (adj[i].size() == 0)
      total++;
    // if(!check[i]) {
    for (auto edge : adj[i]) {
      // int diff = edge.second;
      // cout<<i<<" "<<edge.first<<" "<<h[i]<<" "<<h[edge.first]<<"\\n";
      if (h[i] > h[edge.first]) {
        // if(h[i] != h[edge.first]) check[edge.first] = true;
        oop = 1;

      } else {
        oop = 0;
        break;
      }
    }
    if (oop == 1)
      total++;
    //}
    // cout<<"\\n";
    // check[i] = true;
  }
  cout << total;
  return 0;
}

Error: -11

Fixed submission:

/*#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {

        ll n,total = 0;
        cin>>n;
        ll arr[n+1];
        multiset <ll> str;
        multiset <ll> :: iterator itr1, itr2;
        for(ll i=1; i<=n; i++) {
                cin>>arr[i];
                str.insert(arr[i] + i);
        }
        for(ll i=1; i<=n; i++) {
                ll c = i - arr[i];
                if(c>0) {
                itr1 = str.lower_bound(c);
                itr2 = str.upper_bound(c);
                //cout<<*itr1<<" "<<*itr2<<"\\n";
                total += distance(itr1,itr2);
                }
        }

        cout<<total;
        for(itr1 = str.begin(); itr1!= str.end(); itr1++){
                cout<<*itr1<<" ";
        }

        cout<<distance(itr1,itr2);

        //return 0;
}*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<vector<pair<int, int>>> adj;
int main() {
  int n, m;
  adj.resize(n + 1);
  cin >> n >> m;
  // cout<<n<<m;
  int h[n + 1];
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  int a, b;
  for (int j = 0; j < m; j++) {
    cin >> a >> b;
    adj[a].push_back(make_pair(b, h[a]));
    adj[b].push_back(make_pair(a, h[b]));
  }

  int oop = 0, total = 0;
  vector<bool> check(n + 1, false);
  for (int i = 1; i <= n; i++) {
    oop = 0;
    if (!check[i]) {
      for (auto edge : adj[i]) {
        // int diff = edge.second;
        // cout<<i<<" "<<edge.first<<" "<<h[i]<<" "<<h[edge.first]<<"\\n";
        if (h[i] >= h[edge.first]) {
          check[edge.first] = true;
          oop = 1;

        } else {
          oop = 0;
          break;
        }
      }
      if (oop == 1)
        total++;
    }
    // cout<<"\\n";
    check[i] = true;
  }
  cout << total;
  return 0;
}