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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define int long long
#define lowbit(x) ((x) & (-x))
#define hh putchar('\\n')
#define kg putchar(' ')
using namespace std;
const int maxn = 100005, mod = 20101009;
int n, m, cnt, head[maxn], h[maxn], ans;
struct edge {
  int to, next;
} e[maxn << 1];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
inline void write(int a) {
  if (a < 0) {
    putchar('-');
    putchar('1');
  } else {
    if (a >= 10)
      write(a / 10);
    putchar(a % 10 + '0');
  }
}
void add(int from, int to) {
  e[++cnt] = (edge){to, head[from]};
  head[from] = cnt;
}
signed main() {
  n = read(), m = read();
  for (int i = 1; i <= n; ++i)
    h[i] = read();
  for (int i = 1; i <= m; ++i) {
    int u = read(), v = read();
    add(u, v), add(v, u);
  }
  for (int i = 1; i <= n; ++i) {
    int flag = 0;
    for (int j = head[i]; j; j = e[j].next)
      if (h[e[j].to] >= h[i]) {
        flag = 1;
        break;
      }
    if (!flag)
      ++ans;
  }
  write(ans);
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define int long long
#define lowbit(x) ((x) & (-x))
#define hh putchar('\\n')
#define kg putchar(' ')
using namespace std;
const int maxn = 10005, mod = 20101009;
int n, m, cnt, head[maxn], h[maxn], ans;
struct edge {
  int to, next;
} e[maxn << 1];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
inline void write(int a) {
  if (a < 0) {
    putchar('-');
    putchar('1');
  } else {
    if (a >= 10)
      write(a / 10);
    putchar(a % 10 + '0');
  }
}
void add(int from, int to) {
  e[++cnt] = (edge){to, head[from]};
  head[from] = cnt;
}
signed main() {
  n = read(), m = read();
  for (int i = 1; i <= n; ++i)
    h[i] = read();
  for (int i = 1; i <= m; ++i) {
    int u = read(), v = read();
    add(u, v), add(v, u);
  }
  for (int i = 1; i <= n; ++i) {
    int flag = 0;
    for (int j = head[i]; j; j = e[j].next)
      if (h[e[j].to] >= h[i]) {
        flag = 1;
        break;
      }
    if (!flag)
      ++ans;
  }
  write(ans);
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

// 展望台 i から一本の道を使って辿り着ける展望台の標高の最大値よりも展望台 i
// の標高が高い

#include <algorithm>
#include <iostream>
using namespace std;
#define N 100010
int main() {
  int n, m, h[N],
      ma[N]; // nは展望台の数　mは道の数　h[N]は各展望台の高さ　ma[N]は高い方の展望台
  cin >> n >> m; // 展望台の数と道の数を入力
  for (int i = 1; i <= n; i++) {
    cin >> h[i]; // 各展望台の数を入力　添え字と展望台のナンバリングを合わせてる
    ma[i] = 0;   // ma[N]をそれぞれ初期化
  }
  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; // ansが良い展望台の数
  for (int i = 1; i <= n; i++) {
    ans += h[i] > ma[i];
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

int N, M; // Nは展望台の数　Mは道の本数
vector<int> h;
vector<pair<int, int>> road;

void input() {
  cin >> N >> M;
  h.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> h[i]; // 各展望台の標高を入力
  }
  road.resize(M, pair<int, int>());
  for (int i = 0; i < M; i++) {
    int ra, rb;
    cin >> ra >> rb;
    road[i].first = ra;
    road[i].second = rb;
  }
}

void solve() {
  int ans = N;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < M; j++) {
      if (road[j].first == i) {
        if (h[road[j].first - 1] <= h[road[j].second - 1]) {
          ans--;
          break;
        }
      }
      if (road[j].second == i) {
        if (h[road[j].second - 1] <= h[road[j].first - 1]) {
          ans--;
          break;
        }
      }
    }
  }
  cout << ans << endl;
}

int main() {
  input();
  solve();
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

#define dumpitr(c)                                                             \\
  for (auto itr = c.begin(); itr != c.end(); ++itr) {                          \\
    cout << *itr << " ";                                                       \\
  }                                                                            \\
  cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  vector<int> A(M), B(M);
  vector<bool> NG(N, true);
  int ans = 0;

  rep(i, N) cin >> H[i];
  rep(i, M) {
    cin >> A[i] >> B[i];
    --A[i];
    --B[i];
    if (H[A[i]] <= H[B[i]])
      NG[A[i]] = false;
    if (H[B[i]] <= H[A[i]])
      NG[B[i]] = false;
  }

  // dumpitr(NG);
  rep(i, N) {
    if (NG[i] == true)
      ans += 1;
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <utility>
#include <vector>

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

using ll = long long;

using namespace std;

bool dbg = false;

int N, M;
vector<int> H;

int main(void) {
  cin >> N >> M;
  H = vector<int>(N);
  set<pair<int, int>> st_roads;
  vector<vector<int>> v_roads(M + 1);
  int ans = 0;

  rep(i, N) cin >> H[i];
  rep(i, M) {
    pair<int, int> tmp;
    cin >> tmp.first >> tmp.second;

    if (tmp.first > tmp.second) {
      swap(tmp.first, tmp.second);
    }
    --tmp.first;
    --tmp.second;
    st_roads.insert(tmp);
  }

  for (auto itr = st_roads.begin(); itr != st_roads.end(); ++itr) {
    pair<int, int> tmp;
    tmp = *itr;
    if (dbg)
      cout << "dbg: pair " << tmp.first << ":" << tmp.second << endl;
    v_roads[tmp.first].push_back(tmp.second);
    v_roads[tmp.second].push_back(tmp.first);
  }

  if (dbg) {
    rep(i, N) {
      cout << "dbg: roads:" << i << "->";
      rep(j, v_roads[i].size()) { cout << v_roads[i][j] << " "; }
      cout << endl;
    }
  }

  rep(i, N) {
    bool highest = true;
    if (v_roads[i].size() == 0) {
      highest = true;
      if (dbg)
        cout << "dbg: alone: " << endl;
      continue;
    } else {
      rep(j, v_roads[i].size()) {
        if (H[i] <= H[v_roads[i][j]])
          highest = false;
      }
    }

    if (highest) {
      ans += 1;
      if (dbg)
        cout << "dbg: highest: " << i << endl;
    }
  }

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

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>
#define rep(i, N) for (int i = 0; i < N; i++)
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<long int> H(N);
  vector<int> A(M);
  vector<int> B(M);
  rep(i, N) cin >> H.at(i);
  rep(i, M) cin >> A.at(i) >> B.at(i);
  vector<int> T(N, 1);
  rep(i, M) {
    if (H.at(A.at(i) - 1) > H.at(B.at(i) - 1)) {
      T.at(B.at(i) - 1) = 0;
    } else if (H.at(A.at(i) - 1) == H.at(B.at(i) - 1)) {
      T.at(A.at(i) - 1) = 0;
      T.at(B.at(i) - 1) = 0;
    } else {
      T.at(A.at(i) - 1) = 0;
    }
  }
  int count = 0;
  rep(j, N) {
    int ok = 1;
    if (T.at(j) == 0) {
      ok = 0;
    }
    if (ok == 1) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>
#define rep(i, N) for (int i = 0; i < N; i++)
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<long int> H(N);
  vector<int> A(M);
  vector<int> B(M);
  rep(i, N) cin >> H.at(i);
  rep(i, M) cin >> A.at(i) >> B.at(i);
  vector<vector<int>> T(N, vector<int>(N, -1));
  rep(i, M) {
    if (H.at(A.at(i) - 1) > H.at(B.at(i) - 1)) {
      T.at(A.at(i) - 1).at(B.at(i) - 1) = 1;
      T.at(B.at(i) - 1).at(A.at(i) - 1) = 0;
    } else if (H.at(A.at(i) - 1) == H.at(B.at(i) - 1)) {
      T.at(A.at(i) - 1).at(B.at(i) - 1) = 0;
      T.at(B.at(i) - 1).at(A.at(i) - 1) = 0;
    } else {
      T.at(A.at(i) - 1).at(B.at(i) - 1) = 0;
      T.at(B.at(i) - 1).at(A.at(i) - 1) = 1;
    }
  }
  int count = 0;
  rep(j, N) {
    int ok = 1;
    rep(i, N) {
      if (T.at(j).at(i) == 0) {
        ok = 0;
      }
    }
    if (ok == 1) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = acos(-1);
const int INF = numeric_limits<int>::max();

int main() {
  int n, m;
  cin >> n >> m;

  int h[n];

  rep(i, n) cin >> h[i];

  vector<set<int>> v(n);

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    v[a - 1].insert(b - 1);
    v[b - 1].insert(a - 1);
  }

  int count = 0;

  rep(i, n) {
    bool flag = true;
    set<int>::iterator itr;
    for (itr = v[i].begin(); itr != v[i].end(); ++itr) {
      if (h[i] <= h[*itr])
        flag = false;
    }
    if (flag)
      count++;
  }

  cout << count << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = acos(-1);
const int INF = numeric_limits<int>::max();

int main() {
  int n, m, h[100000];
  cin >> n >> m;

  bool g[m][m];

  rep(i, n) cin >> h[i];

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    g[a][b] = true;
    g[b][a] = true;
  }

  int count = 0;

  rep(i, n) {
    bool flag = true;
    for (int j = 0; j < n; ++j) {
      if (g[i][j] || g[j][i])
        if (h[i] <= h[j])
          flag = false;
    }
    if (flag)
      count++;
  }

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

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
  ll N, M;
  cin >> N >> M;
  if (2 > N || N > 100000) {
    return 0;
  }
  if (1 > M || M > 100000) {
    return 0;
  }

  ll H[N], t[N];
  REP(i, N) {
    cin >> H[i];
    if (1 > H[i] || H[i] > 1000000000) {
      return 0;
    }
    t[i] = 1;
  }

  ll A[M], B[M];
  REP(i, M) {
    cin >> A[i] >> B[i];
    if (1 > A[i] || A[i] > N || 1 > B[i] || B[i] > N) {
      return 0;
    }
    if (A[i] == B[i]) {
      return 0;
    }
  }

  int ans = 0, tmp = 0;
  /*REP(i, N){
      tmp = 0;
      if(C[i]==1){
          REP(j, M){
              if(A[j]==i+1){
                  if(H[B[j]-1] >= H[i]){
                      tmp = 1;
                      break;
                  }
              }
              if(B[j]==i+1){
                  if(H[A[j]-1] >= H[i]){
                      tmp = 1;
                      break;
                  }
              }
          }
          if(tmp==0){
              //cout << i+1 << "\\n";
              ans++;
          }
      }
      else{
          ans++;
      }
  }*/

  REP(i, M) {
    if (H[A[i] - 1] > H[B[i] - 1]) {
      t[B[i] - 1] = 0;
      // cout << B[i] << H[B[i]-1] << "\\n";
    } else if (H[A[i] - 1] < H[B[i] - 1]) {
      t[A[i] - 1] = 0;
      // cout << A[i] << H[A[i]-1] << "\\n";
    } else if (H[A[i] - 1] == H[B[i] - 1]) {
      t[A[i] - 1] = 0;
      t[B[i] - 1] = 0;
      // cout << A[i] << H[A[i]-1] << B[i] << H[B[i]-1] << "\\n";
    }
  }

  REP(i, N) { ans += t[i]; }

  cout << ans;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
  ll N, M;
  cin >> N >> M;
  if (2 > N || N > 100000) {
    return 0;
  }
  if (1 > M || M > 100000) {
    return 0;
  }

  ll H[N];
  REP(i, N) {
    cin >> H[i];
    if (1 > H[i] || H[i] > 1000000000) {
      return 0;
    }
  }

  ll A[M], B[M];
  REP(i, M) {
    cin >> A[i] >> B[i];
    if (1 > A[i] || A[i] > N || 1 > B[i] || B[i] > N) {
      return 0;
    }
    if (A[i] == B[i]) {
      return 0;
    }
  }

  int ans = 0, tmp = 0;
  REP(i, N) {
    tmp = 0;
    REP(j, M) {
      if (A[j] == i + 1) {
        if (H[B[j] - 1] >= H[i]) {
          tmp = 1;
          break;
        }
      }
      if (B[j] == i + 1) {
        if (H[A[j] - 1] >= H[i]) {
          tmp = 1;
          break;
        }
      }
    }
    if (tmp == 0) {
      // cout << i+1 << "\\n";
      ans++;
    }
  }

  cout << ans;

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

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, m;
  int a, b;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> ok(n, true);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

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

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (ok[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 <iostream>
#include <vector>
using namespace std;

int main() {
  int n, m;
  int a, b;
  vector<int> h(n);
  vector<bool> ok(n, true);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

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

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

  cout << ans << endl;

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

#include <bits/stdc++.h>

//    int n=132;
//    bitset<16>binar(n);
//    int a = bitset<16>(binar).to_ulong();
//    cout<<a;

#define int long long
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(c) (c).begin(), (c).end()

using namespace std;

signed main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, 0, n) { cin >> a[i]; }
  int l, r;
  vector<int> ans(n, 1);
  rep(i, 0, m) {
    cin >> l >> r;
    l--;
    r--;
    if (a[l] >= a[r]) {
      ans[r] = 0;
    }
    if (a[l] <= a[r]) {
      ans[l] = 0;
    }
  }
  int val = accumulate(all(ans), 0);
  cout << val;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

//    int n=132;
//    bitset<16>binar(n);
//    int a = bitset<16>(binar).to_ulong();
//    cout<<a;

#define int long long
#define pb push_back
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(c) (c).begin(), (c).end()

using namespace std;

signed main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, 0, n) { cin >> a[i]; }
  int l, r;
  vector<int> ans(n, 1);
  rep(i, 0, m) {
    cin >> l >> r;
    if (a[l] >= a[r]) {
      ans[r] = 0;
    } else if (a[l] <= a[r]) {
      ans[l] = 0;
    }
  }
  int val = accumulate(all(ans), 0);
  cout << val;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define N 100010
int main() {
  using namespace std;
  int n, m, h[N], ma[N];
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> h[i];
    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)
    ans += h[i] > ma[i];
  cout << ans << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define N 10010
int main() {
  using namespace std;
  int n, m, h[N], ma[N];
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> h[i];
    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)
      ans += h[i] > ma[i];
    cout << ans << endl;
  }
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <ctype.h>
#include <iostream>
#include <math.h>
#include <stack>
#include <string.h>
#include <string>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;
const long INF = 2000000000;

int main() {
  int n, m, h[110000], ma[110000];
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    ma[i] = 0;
  }
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    ma[a] = max(ma[a], h[b]);
    ma[b] = max(ma[b], h[a]);
  }

  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (h[i] > ma[i])
      cnt++;

  cout << cnt << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <ctype.h>
#include <iostream>
#include <math.h>
#include <stack>
#include <string.h>
#include <string>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;
const long INF = 2000000000;

int main() {
  int n, m, h[110000], a[110000], b[110000];
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  for (int i = 1; i <= m; i++)
    cin >> a[i] >> b[i];

  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    int ma = 0;
    for (int j = 1; j <= m; j++) {
      if (a[j] == i)
        ma = max(ma, h[b[j]]);
      if (b[j] == i)
        ma = max(ma, h[a[j]]);
    }
    if (h[i] > ma)
      cnt++;
  }
  cout << cnt << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

/*input
6 5
8 6 9 1 2 1
1 3
4 2
4 3
4 6
4 6
*/

#include <bits/stdc++.h>

using namespace std;

const int Nmax = 1e5 + 10;

int n, m, res;
vector<int> a[Nmax];
int h[Nmax];

int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> h[i];
  }
  while (m--) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  for (int u = 1; u <= n; ++u) {
    bool found = false;
    for (auto v : a[u]) {
      if (h[v] >= h[u]) {
        found = true;
        break;
      }
    }
    if (found == false)
      res++;
  }
  cout << res << endl;
}

Error: 0

Fixed submission:

/*input
6 5
8 6 9 1 2 1
1 3
4 2
4 3
4 6
4 6
*/

#include <bits/stdc++.h>

using namespace std;

const int Nmax = 1e5 + 10;

int n, m, res;
vector<int> a[Nmax];
int h[Nmax];

int main() {
  cin >> n >> m;
  while (m--) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
  }
  for (int i = 1; i <= n; ++i) {
    cin >> h[i];
  }
  for (int u = 1; u <= n; ++u) {
    bool found = false;
    for (auto v : a[u]) {
      if (h[v] >= h[u]) {
        found = true;
        break;
      }
    }
    if (found == false)
      res++;
  }
  cout << res << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <list>
#include <unordered_map>
#include <vector>
using namespace std;

int main() {

  int *H = new int[100001];
  int *B = new int[100001];
  int N, M;
  cin >> N >> M;

  for (int i = 1; i < N + 1; i++) {
    cin >> H[i];
  }

  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    if (H[a] > H[b]) {
      B[b]++;
    } else if (H[a] < H[b]) {
      B[a]++;
    } else {
      B[b]++;
      B[a]++;
    }
  }
  int cnt = 0;
  for (int i = 1; i < N + 1; i++) {
    if (B[i] == 0) {
      cnt++;
    }
  }
  cout << cnt << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {
  // vector<vector<int>> B(100001, vector<int>(100001));
  int **B = new int *[100001];
  // 配列の各要素でintの配列を動的生成
  for (int i = 0; i < 100001; i++) {
    B[i] = new int[100001];
  }
  // int B[100001][100001];
  int *H = new int[100001];
  int N, M;
  cin >> N >> M;

  for (int i = 1; i < N + 1; i++) {
    cin >> H[i];
  }

  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    // B.at(a).at(b)++;
    // B.at(b).at(a)++;
    B[a][b]++;
    B[b][a]++;
  }
  int cnt = 0;
  for (int i = 1; i < N + 1; i++) {
    int max = H[i];
    for (int j = 1; j < N + 1; j++) {
      if (B[i][j] > 0) {
        if (max <= H[j]) {
          max = 0;
          break;
        }
      }
    }
    if (max == H[i]) {
      cnt++;
    }
  }
  cout << cnt << endl;

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

// By Shreehari Bodas

#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7;

int search(int b[], int m, int s) {
  int start = 0, end = m - 1;
  bool flag = false;
  while (start <= end) {
    int mid = (start + end) / 2;
    if (b[mid] == s) {
      flag = true;
      return mid;
    } else if (b[mid] > s)
      end = mid - 1;
    else if (b[mid] < s)
      start = mid + 1;
  }
  if (flag == false)
    return m;
}

long long int pow(long long int a, long long int b) {
  if (b == 0)
    return 1;
  long long int res = pow(a, b / 2);
  if (b % 2 == 1)
    return res * res * a;
  else if (b % 2 == 0)
    return res * res;
}

int main() {

  int n, m;
  cin >> n >> m;
  int good[n];
  for (int i = 0; i < n; i++)
    good[i] = true;

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

  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    if (h[u - 1] > h[v - 1])
      good[v - 1] = false;
    else if (h[v - 1] > h[u - 1])
      good[u - 1] = false;
    else if (h[v - 1] == h[u - 1]) {
      good[v - 1] = false;
      good[u - 1] = false;
    }
  }

  int count = 0;
  for (int i = 0; i < n; i++) {
    if (good[i] == true)
      count++;
  }

  cout << count << endl;

  return 0;
}

Error: 0

Fixed submission:

// By Shreehari Bodas

#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7;

int search(int b[], int m, int s) {
  int start = 0, end = m - 1;
  bool flag = false;
  while (start <= end) {
    int mid = (start + end) / 2;
    if (b[mid] == s) {
      flag = true;
      return mid;
    } else if (b[mid] > s)
      end = mid - 1;
    else if (b[mid] < s)
      start = mid + 1;
  }
  if (flag == false)
    return m;
}

long long int pow(long long int a, long long int b) {
  if (b == 0)
    return 1;
  long long int res = pow(a, b / 2);
  if (b % 2 == 1)
    return res * res * a;
  else if (b % 2 == 0)
    return res * res;
}

int main() {

  int n, m;
  cin >> n >> m;
  int h[n];
  vector<int> adj[n];

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

  int good = n;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < adj[i].size(); j++) {
      if (h[i] <= h[adj[i][j]]) {
        good--;
        break;
      }
    }
  }

  cout << good << endl;

  return 0;
}