alexjercan/bugnet huggingface dataset:
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define pb push_back
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
#define sort_1(v) sort(v.begin(), v.end())
#define sort_2(v) sort(v.begin(), v.end(), greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;

int main() {
  ll n, m;
  cin >> n >> m;
  map<ll, ll> mp;
  ll h[n + 1];
  for (ll i = 1; i <= n; i++)
    cin >> h[i];
  vector<ll> a(m), b(m);
  rep(i, m) {
    cin >> a[i] >> b[i];
    if (h[a[i]] > h[b[i]]) {
      mp[b[i]] = 1;
    }
    if (h[a[i]] < h[b[i]]) {
      mp[a[i]] = 1;
    }
    if (h[a[i]] == h[b[i]]) {
      if (mp[a[i]] != 1) {
        mp[a[i]] = 1;
      }
      if (mp[b[i]] != 1) {
        mp[b[i]] = 1;
      }
    }
  }
  cout << n - mp.size() << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
#define sort_1(v) sort(v.begin(), v.end())
#define sort_2(v) sort(v.begin(), v.end(), greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;

int main() {
  ll n, m;
  cin >> n >> m;
  map<ll, ll> mp;
  ll h[n + 1];
  for (ll i = 1; i <= n; i++)
    cin >> h[i];
  vector<int> a(n), b(n);
  rep(i, m) { cin >> a[i] >> b[i]; }
  rep(i, m) {
    if (h[a[i]] > h[b[i]]) {
      mp[b[i]] = 1;
    }
    if (h[a[i]] < h[b[i]]) {
      mp[a[i]] = 1;
    }
    if (h[a[i]] == h[b[i]]) {
      if (mp[a[i]] != 1) {
        mp[a[i]] = 1;
      }
      if (mp[b[i]] != 1) {
        mp[b[i]] = 1;
      }
    }
  }
  cout << n - mp.size() << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  int N, M;
  cin >> N >> M;
  ll H[N];
  rep(i, N) { cin >> H[i]; }

  int b[N];

  rep(i, N) { b[i] = 1; }

  rep(i, M) {
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;

    if (H[tmp1 - 1] >= H[tmp2 - 1]) {
      b[tmp2 - 1] = -1;
    }
    if (H[tmp2 - 1] >= H[tmp1 - 1]) {
      b[tmp1 - 1] = -1;
    }
  }
  int ans = 0;
  rep(i, N) {
    if (b[i] == 1) {
      ans++;
    }
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  int N, M;
  cin >> N >> M;
  int H[N];
  rep(i, N) { cin >> H[i]; }
  vector<vector<int>> mat(N, vector<int>(N));

  rep(i, M) {
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    mat.at(tmp1 - 1).at(tmp2 - 1) = 1;
    mat.at(tmp2 - 1).at(tmp1 - 1) = 1;
  }
  int ans = 0;
  rep(i, N) {
    bool tmp = true;

    if (accumulate(mat.at(i).begin(), mat.at(i).end(), 0) == 0) {
      ans++;
      continue;
    } else {
      rep(j, N) {
        if (mat.at(i).at(j) == 0) {
          continue;
        } else if ((mat.at(i).at(j) == 1) && (H[i] > H[j])) {
          continue;
        } else {
          tmp = false;
          break;
        }
      }
      if (tmp) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

// created by pyoxiao on 2020/05/03
#include <bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define CL(a, b) memset(a, b, sizeof(a))
using namespace std;
const int mod = 1e9 + 7;
LL fpow(LL a, LL b, LL p = mod) {
  LL ans = 1;
  a %= p;
  while (b) {
    if (b & 1)
      ans = ans * a % p;
    b >>= 1;
    a = a * a % p;
  }
  return ans;
}
LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a % b); }
int n, m, h[100010];
vector<int> ver[100010];
void solve() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", h + i);
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    ver[a].pb(b);
    ver[b].pb(a);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    bool ok = 1;
    for (auto to : ver[i]) {
      if (h[to] >= h[i]) {
        ok = 0;
        break;
      }
    }
    if (ok)
      ans++;
  }
  printf("%d\\n", ans);
}
int main() {
  int T = 1;
  // scanf("%d", &T);
  while (T--)
    solve();
  return 0;
}

Error: 0

Fixed submission:

// created by pyoxiao on 2020/05/03
#include <bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define CL(a, b) memset(a, b, sizeof(a))
using namespace std;
const int mod = 1e9 + 7;
LL fpow(LL a, LL b, LL p = mod) {
  LL ans = 1;
  a %= p;
  while (b) {
    if (b & 1)
      ans = ans * a % p;
    b >>= 1;
    a = a * a % p;
  }
  return ans;
}
LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a % b); }
int n, m, h[10010];
vector<int> ver[10010];
void solve() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", h + i);
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    ver[a].pb(b);
    ver[b].pb(a);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    bool ok = 1;
    for (auto to : ver[i]) {
      if (h[to] >= h[i]) {
        ok = 0;
        break;
      }
    }
    if (ok)
      ans++;
  }
  printf("%d\\n", ans);
}
int main() {
  int T = 1;
  // scanf("%d", &T);
  while (T--)
    solve();
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long n, m, ans = 0;
  cin >> n >> m;
  vector<long long> h(n), a(m), b(m), Mt(n);
  for (long long i = 0; i < n; i++) {
    cin >> h.at(i);
  }
  for (long long i = 0; i < m; i++) {
    cin >> a.at(i) >> b.at(i);
    if (h.at(a.at(i) - 1) > h.at(b.at(i) - 1))
      Mt.at(b.at(i) - 1) = -1;
    else if (h.at(a.at(i) - 1) < h.at(b.at(i) - 1))
      Mt.at(a.at(i) - 1) = -1;
    else {
      Mt.at(a.at(i) - 1) = -1;
      Mt.at(b.at(i) - 1) = -1;
    }
  }

  for (long long i = 0; i < n; i++) {
    if (Mt.at(i) == 0)
      ans++;
  }

  cout << ans << endl;

  return 0;
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)


Fixed submission:

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

int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  vector<int> h(n), a(m), b(m), Mt(n);
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
  }
  for (int i = 0; i < n; i++) {
    cin >> a.at(i) >> b.at(i);
    if (h.at(a.at(i) - 1) >= h.at(b.at(i) - 1))
      Mt.at(b.at(i) - 1) = -1;
    else if (h.at(a.at(i) - 1) <= h.at(b.at(i) - 1))
      Mt.at(a.at(i) - 1) = -1;
  }

  for (int i = 0; i < n; i++) {
    if (Mt.at(i) == 0)
      ans++;
  }

  cout << ans << endl;

  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for (ll i = (m); i < (n); i++)
#define all(v) v.begin(), v.end()
#define print(x) cout << (x) << endl

int main() {
  int N, M, A, B, h;
  cin >> N >> M;
  vector<int> H(N);
  vector<bool> ii(N, true);

  rep(i, N) {
    cin >> h;
    H.at(i) = h;
  }
  rep(i, M) {
    cin >> A >> B;
    if (H.at(A - 1) == H.at(B - 1)) {
      ii.at(A - 1) = false;
      ii.at(B - 1) = false;
    } else {
      if (H.at(A - 1) > H.at(B - 1)) {
        ii.at(B - 1) = false;
      } else {
        ii.at(A - 1) = false;
      }
    }
  }
  int cnt = 0;
  rep(i, N) {
    if (ii.at(i))
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for (ll i = (m); i < (n); i++)
#define all(v) v.begin(), v.end()
#define print(x) cout << (x) << endl

int main() {
  int N, M, A, B, h;
  vector<int> H(N);
  vector<bool> ii(N, true);
  cin >> N >> M;
  rep(i, N) {
    cin >> h;
    H.at(i) = h;
  }
  rep(i, M) {
    cin >> A >> B;
    if (H.at(A - 1) == H.at(B - 1)) {
      ii.at(A - 1) = false;
      ii.at(B - 1) = false;
    } else {
      if (H.at(A - 1) > H.at(B - 1)) {
        ii.at(B - 1) = false;
      } else {
        ii.at(A - 1) = false;
      }
    }
  }
  int cnt = 0;
  rep(i, N) {
    if (ii.at(i))
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  /* Input */
  int N, M;
  cin >> N >> M;
  vector<long int> H(N);
  rep(i, N) cin >> H.at(i);

  vector<long int> max_hights(N);
  rep(i, N) max_hights.at(i) = 0;

  vector<int> A(M);
  vector<int> B(M);
  rep(i, M) cin >> A.at(i) >> B.at(i);

  /* Main Logic */
  int nice = 0;
  long int max_height = 0;
  rep(i, M) {
    max_hights.at(A.at(i) - 1) =
        max(max_hights.at(A.at(i) - 1), H.at(B.at(i) - 1));
    max_hights.at(B.at(i) - 1) =
        max(max_hights.at(B.at(i) - 1), H.at(A.at(i) - 1));
  }

  rep(i, N) if (max_hights.at(i) < H.at(i)) nice++;

  /* Output */
  cout << nice << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  /* Input */
  int N, M;
  cin >> N >> M;
  vector<long int> H(N);
  rep(i, N) cin >> H.at(i);
  vector<int> A(M);
  vector<int> B(M);
  rep(i, M) cin >> A.at(i) >> B.at(i);

  /* Main Logic */
  int nice = 0;
  rep(i, N) {
    long int max_height = 0;
    rep(j, M) {
      if (i == A.at(j) - 1)
        max_height = max(max_height, H.at(B.at(j) - 1));
      if (i == B.at(j) - 1)
        max_height = max(max_height, H.at(A.at(j) - 1));
      if (max_height >= H.at(i))
        break;
    }
    if (max_height < H.at(i))
      nice++;
  }

  /* Output */
  cout << nice << endl;

  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> high(N);
  vector<int> vec(N, 1);

  rep(i, N) cin >> high.at(i);

  rep(i, M) {
    int A, B;
    cin >> A >> B;
    A--;
    B--;

    if (high.at(A) <= high.at(B))
      vec.at(A) = 0;
    if (high.at(B) <= high.at(A))
      vec.at(B) = 0;
  }

  int count = 0;

  rep(i, N) count += vec.at(i);

  cout << count << endl;
}


Error: 0

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> high(N);
  vector<vector<int>> vec(N, vector<int>(N));

  rep(i, N) cin >> high.at(i);

  rep(i, M) {
    int A, B;
    cin >> A >> B;
    A--;
    B--;

    vec.at(A).at(B) = high.at(B);
    vec.at(B).at(A) = high.at(A);
  }
  rep(i, N) { sort(vec.at(i).begin(), vec.at(i).end()); }

  int count = 0;

  rep(i, N) if (vec.at(i).at(N - 1) < high.at(i)) count++;

  cout << count << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::vector;

int main() {
  unsigned int ans = 0;
  unsigned int n, m;
  vector<unsigned long> h;
  vector<bool> good;
  unsigned long height;
  unsigned int a, b;
  typedef struct {
    unsigned int a;
    unsigned int b;
  } ROUTE;
  vector<ROUTE> rt;

  // input
  cin >> n >> m;
  for (unsigned int i = 0; i < n; i++) {
    cin >> height;
    h.push_back(height);
    good.push_back(true);
  }
  for (unsigned int i = 0; i < m; i++) {
    ROUTE r;
    cin >> a >> b;
    if (a < b) {
      r.a = a;
      r.b = b;
    } else {
      r.a = b;
      r.b = a;
    }
    rt.push_back(r);
  }

  // calc
  for (unsigned int i = 0; i < m; i++) {
    unsigned int aidx = rt[i].a - 1;
    unsigned int bidx = rt[i].b - 1;
    if (h[aidx] < h[bidx]) {
      good[aidx] = false;
    } else if (h[aidx] > h[bidx]) {
      good[bidx] = false;
    } else {
      good[aidx] = false;
      good[bidx] = false;
    }
  }
  for (unsigned int i = 0; i < n; i++) {
    if (good[i])
      ans++;
  }

  // output
  cout << ans;
  cout << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::vector;

int main() {
  unsigned int ans = 0;
  unsigned int n, m;
  vector<unsigned long> h;
  unsigned long height;
  typedef struct {
    unsigned int a;
    unsigned int b;
  } ROUTE;
  vector<ROUTE> rt;

  // input
  cin >> n >> m;
  for (unsigned int i = 0; i < n; i++) {
    cin >> height;
    h.push_back(height);
  }
  for (unsigned int i = 0; i < m; i++) {
    ROUTE r;
    cin >> r.a >> r.b;
    rt.push_back(r);
  }

  // calc
  for (unsigned int i = 0; i < n; i++) {
    bool good = true;
    for (unsigned int j = 0; j < m; j++) {
      unsigned int here = i + 1;
      unsigned int there = 0;
      if (here == rt[j].a) {
        there = rt[j].b;
      } else if (here == rt[j].b) {
        there = rt[j].a;
      }
      if (0 != there) {
        if (h[here - 1] <= h[there - 1]) {
          good = false;
          break;
        }
      }
    }
    if (good) {
      ans++;
    }
  }

  // output
  cout << ans;
  cout << endl;

  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n, m;
  cin >> n >> m;

  int h[n];
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

  bool ok[n];
  fill(ok, ok + n, true);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (h[a] > h[b])
      ok[b] = false;
    else if (h[a] < h[b])
      ok[a] = false;
    else {
      ok[a] = false;
      ok[b] = false;
    }
  }

  int ret = 0;
  for (int i = 0; i < n; i++) {
    if (ok[i]) {
      ret++;
    }
  }

  cout << ret << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

bool ok(vector<vector<int>> adj, int i, vector<int> heights) {
  if (adj[i].size() == 0)
    return true;

  for (int nbr : adj[i]) {
    if (heights[nbr] >= heights[i])
      return false;
  }
  return true;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n, m;
  cin >> n >> m;

  vector<vector<int>> adj;
  for (int i = 0; i < n; i++) {
    vector<int> v;
    adj.push_back(v);
  }

  vector<int> h;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    h.push_back(a);
  }

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }

  int ret = 0;
  for (int i = 0; i < n; i++) {
    if (ok(adj, i, h))
      ret++;
  }

  cout << ret << endl;

  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
using P = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define PI acos(-1)
#define fast_io                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
ll mod = 1e9 + 7;

int main() {
  fast_io

      ll n,
      m;
  cin >> n >> m;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  bool path[100010] = {};

  rep(i, m) {
    ll a;
    ll b;
    cin >> a >> b;
    a -= 1;
    b -= 1;
    if (h[a] < h[b]) {
      path[a] = true;
    } else if (h[a] > h[b]) {
      path[b] = true;
    } else {
      path[a] = true;
      path[b] = true;
    }
  }
  ll ans = 0;

  rep(i, n) {
    if (!path[i])
      ans++;
  }

  cout << ans << endl;

  return 0;
}


Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
using P = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define PI acos(-1)
#define fast_io                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
ll mod = 1e9 + 7;

int main() {
  fast_io

      ll n,
      m;
  cin >> n >> m;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  vector<vector<int>> path(100100, vector<int>(100100, 1));

  rep(i, m) {
    ll a;
    ll b;
    cin >> a >> b;
    a -= 1;
    b -= 1;
    if (h[a] < h[b]) {
      path[a][b] = false;
    } else if (h[a] > h[b]) {
      path[b][a] = false;
    } else {
      path[a][b] = false;
      path[b][a] = false;
    }
  }
  ll ans = 0;

  rep(i, n) {
    bool flag = true;
    rep(j, n) {
      if (i == j)
        continue;
      if (!path[i][j]) {
        flag = false;
        break;
      }
    }
    if (flag)
      ans++;
  }

  cout << ans << endl;

  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int n, m, cnt, ans, head[1100000], h[1100000];
struct road {
  int to;
  int next;
} road[1100000];
void add(int u, int v) {
  ++cnt;
  road[cnt].to = v;
  road[cnt].next = head[u];
  head[u] = cnt;
}
int check(int t) {
  for (int i = head[t]; i; i = road[i].next) {
    if (h[t] <= h[road[i].to])
      return 0;
  }
  return 1;
}
int main(void) {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    add(u, v);
    add(v, u);
  }
  for (int i = 1; i <= n; i++) {
    if (check(i)) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int n, m, cnt, ans, head[110000], h[110000];
struct road {
  int to;
  int next;
} road[110000];
void add(int u, int v) {
  ++cnt;
  road[cnt].to = v;
  road[cnt].next = head[u];
  head[u] = cnt;
}
int check(int t) {
  for (int i = head[t]; i; i = road[i].next) {
    if (h[t] <= h[road[i].to])
      return 0;
  }
  return 1;
}
int main(void) {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    add(u, v);
    add(v, u);
  }
  for (int i = 1; i <= n; i++) {
    if (check(i)) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
// vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000
#define ll long long
#define ln cout << endl;
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define double long double
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll c, d, n, m, maxi = 0, f = 0, mini = INF, sum = 0;
  string str;
  cin >> n >> m;

  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  vector<ll> tf(n);
  rep(i, n) tf[i] = 1;
  vector<ll> a(n);
  vector<ll> b(m);
  rep(i, m) {
    cin >> c >> d;
    a[c - 1] = max(a[c - 1], h[d - 1]);
    a[d - 1] = max(a[d - 1], h[c - 1]);
  }
  rep(i, n) {
    if (a[i] < h[i])
      sum++;
  }

  cout << sum << endl;
  return 0;
}


Error: TLE

Fixed submission:

// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
// vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000
#define ll long long
#define ln cout << endl;
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define double long double
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll c, d, n, m, maxi = 0, f = 0, mini = INF, sum = 0;
  string str;
  cin >> n >> m;

  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  vector<ll> tf(n);
  rep(i, n) tf[i] = 1;
  vector<ll> a(m);
  vector<ll> b(m);
  rep(i, m) { cin >> a[i] >> b[i]; }
  rep(i, n) {
    if (tf[i] == 0)
      continue;

    rep(j, m) {
      if (a[j] == i + 1) {
        if (h[i] <= h[b[j] - 1]) {
          tf[i] = 0;
        } else {
          tf[b[j] - 1] = 0;
        }
        if (h[i] == h[b[j] - 1])
          tf[b[j] - 1] = 0;
      } else if (b[j] == i + 1) {
        if (h[i] <= h[a[j] - 1]) {
          tf[i] = 0;
          // cout<<h[b[j]]<<" "<<h[i]<<endl;

        } else {
          tf[a[j] - 1] = 0;
        }
        if (h[i] == h[a[j] - 1])
          tf[a[j] - 1] = 0;
      }
      if (tf[i] == 0)
        break;
    }
    if (tf[i] == 1) {
      sum++;
      // cout<<i+1<<"  ";
    }
  }

  cout << sum << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m, h[200010], ma[200010];
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    ll height;
    cin >> height;
    h[i] = height;
    ma[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (h[i] > ma[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)


Fixed submission:

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

int main() {
  int64_t N, M;
  cin >> N >> M;

  vector<int64_t> H(N + 1);
  for (int i = 1; i <= N; i++) {
    int height;
    cin >> height;
    H.at(i) = height;
  }

  set<pair<int, int>> R;

  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    if (A > B) {
      swap(A, B);
    }
    R.insert(make_pair(A, B));
  }

  vector<vector<int>> S(N + 1);

  for (auto x : R) {
    S.at(x.first).push_back(x.second);
    S.at(x.second).push_back(x.first);
  }
  int cnt = 0;
  for (int i = 1; i <= N; i++) {
    if (S.at(i).size() == 0) {
      cnt++;
      break;
    }
    for (int j = 1; j < S.at(i).size(); j++) {
      if (H.at(i) < H.at(S.at(i).at(j))) {
        break;
      }
      if (j == S.at(i).at(S.at(i).size())) {
        if (H.at(i) > H.at(S.at(i).at(S.at(i).size()))) {
          cnt++;
        }
      }
    }
  }
  cout << cnt << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    g[a - 1].push_back(h[b - 1]);
    g[b - 1].push_back(h[a - 1]);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (g[i].size() == 0)
      ans++;
    else {
      bool tf = true;
      for (int j = 0; j < g[i].size(); j++) {
        if (h[i] <= g[i][j])
          tf = false;
      }
      if (tf)
        ans++;
    }
  }
  cout << ans;
  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vector<vector<int>> g;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    g[a - 1].push_back(b);
    g[b - 1].push_back(a);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (g[i].size() == 0)
      ans++;
    else {
      bool tf = true;
      for (int j = 0; j < g[i].size(); j++) {
        if (h[i] < g[i][j])
          tf = false;
      }
      if (tf)
        ans++;
    }
  }
  cout << ans;
  return 0;
}