alexjercan/bugnet huggingface dataset:
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

  for (size_t i = 1; i <= N; i++) {
    cin >> H[i];
  }
  for (size_t i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
  }

  for (size_t i = 0; i < M; i++) {
    if (H[A[i]] <= H[B[i]]) {
      C[A[i]] = false;
    }
    if (H[B[i]] <= H[A[i]]) {
      C[B[i]] = false;
    }
  }

  for (size_t i = 1; i <= N; i++) {
    if (C[i] == true) {
      ans += 1;
    }
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

  for (size_t i = 0; i < N; i++) {
    cin >> H[i];
  }
  for (size_t i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
  }

  for (size_t i = 0; i < N; i++) {
    for (size_t j = 0; j < M; j++) {
      if (i == A[j] - 1 && H[i] <= H[B[j] - 1]) {
        C[i] = false;
        break;
      } else if (i == B[j] - 1 && H[i] <= H[A[j] - 1]) {
        C[i] = false;
        break;
      }
    }
  }

  for (size_t i = 0; i < N; i++) {
    if (C[i] == true) {
      ans += 1;
    }
  }

  cout << ans << endl;

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

#include <iostream>
int a[100010];
bool h[100010];
using namespace std;

int main() {
  int n, m, f = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (a[x] <= a[y])
      h[x] = 1;
    if (a[y] <= a[x])
      h[y] = 1;
  }
  for (int i = 1; i <= n; i++)
    if (!h[i])
      f++;
  cout << f << endl;
}

Error: 0

Fixed submission:

#include <iostream>
int a[100010];
bool h[100010], H[100010];
using namespace std;

int main() {
  int n, m, F = 0, f = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    H[i] = 1;
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    H[x] = H[y] = 0;
    if (a[x] && a[y] && a[x] != a[y])
      h[max(a[x], a[y])] = 1;
  }
  for (int i = 0; i < 100010; i++) {
    if (h[i])
      f++;
    if (H[i])
      f++;
  }
  cout << f << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) loop(i, 0, n)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>

int main() {
  ll int n, m;
  cin >> n >> m;
  vl h(n);
  rep(i, n) cin >> h[i];
  vl a(m), b(m);
  rep(i, m) cin >> a[i] >> b[i];
  vector<vector<int>> net(n);

  rep(i, m) {
    net[a[i] - 1].push_back(b[i] - 1);
    net[b[i] - 1].push_back(a[i] - 1);
  }

  rep(i, n) { sort(all(net[i])); }

  int ans = 0;
  rep(i, n) {
    ll int hi = h[i];
    int flag = 0;
    int ini;
    if (net[i].size() > 0) {
      ini = net[i][0];
      for (long unsigned int j = 0; j < net[i].size(); j++) {
        if (j != 0 && ini == net[i][j])
          continue;
        if (hi <= h[net[i][j]]) {
          ini = net[i][j];
          flag = 1;
        }
      }
    }

    if (flag == 0)
      ans++;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) loop(i, 0, n)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>

int main() {
  ll int n, m;
  cin >> n >> m;
  vl h(n);
  rep(i, n) cin >> h[i];
  vl a(m), b(m);
  rep(i, m) cin >> a[i] >> b[i];
  vector<vector<int>> net(n);

  rep(i, m) {
    net[a[i] - 1].push_back(b[i] - 1);
    net[b[i] - 1].push_back(a[i] - 1);
  }

  rep(i, m) { sort(all(net[i])); }

  int ans = 0;
  rep(i, n) {
    ll int hi = h[i];
    int flag = 0;
    int ini;
    if (net[i].size() > 0) {
      ini = net[i][0];
      for (long unsigned int j = 0; j < net[i].size(); j++) {
        if (j != 0 && ini == net[i][j])
          continue;
        if (hi <= h[net[i][j]]) {
          ini = net[i][j];
          flag = 1;
        }
      }
    }

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

#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define db(x) cout << "> " << #x << ": " << x << "\\n";
#define ss cout << " ";
#define ct(x) cout << x;
#define nn cout << "\\n";
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\\n";
// // // // // // // // // // // // // // // // // // //
int64 q, n;

void solve() { return; }
const int MAXN = 1e5 + 100;
vector<int64> L(MAXN);

int main() {
  int64 n, k;
  cin >> n >> k;
  vec64 arr(MAXN);
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (int i = 1; i <= k; i++) {
    int64 a, b;
    cin >> a >> b;
    L[a] = max(L[a], arr[b]);
    L[b] = max(L[b], arr[a]);
    // cts(a); ctn(b);
  }
  int64 rs = 0;
  // nn;
  for (int i = 1; i <= n; i++) {
    // cout << arr[i] << " " << L[i] << "\\n";
    if (arr[i] > L[i]) {
      rs++;
    }
  }
  ctn(rs);
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define db(x) cout << "> " << #x << ": " << x << "\\n";
#define ss cout << " ";
#define ct(x) cout << x;
#define nn cout << "\\n";
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\\n";
// // // // // // // // // // // // // // // // // // //
int64 q, n;

void solve() { return; }
const int MAXN = 1e5 + 100;
vector<int64> L[MAXN];

int main() {
  int64 n, k;
  cin >> n >> k;
  vec arr(n);
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (int i = 1; i <= k; i++) {
    int64 a, b;
    cin >> a >> b;
    L[a].push_back(b);
    L[b].push_back(a);
    // cts(a); ctn(b);
  }
  int64 rs = 0;
  for (int i = 1; i <= n; i++) {
    int64 cur = arr[i];
    bool flag = 0;
    // cts(i);
    if (L[i].size() == 0) {
      rs++;
      continue;
    }
    for (auto i : L[i]) {
      // cts(L[i][j]);
      if (arr[i] < cur && !flag) {
        rs++;
        flag = 1;
      }
    }
    // nn;
  }
  ctn(rs);
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main(void) {
  long long int N, M, a_i, b_i, a, b;
  long long int height[100000];
  long long int bad[100000] = {};
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> height[i];
  }
  long long int count = 0;
  for (long long int i = 0; i < M; i++) {
    cin >> a_i >> b_i;
    a = a_i - 1;
    b = b_i - 1;
    if (bad[a] == 0) {
      if (height[a] <= height[b]) {
        count++;
        bad[a] = 1;
      }
    }
    if (bad[b] == 0) {
      if (height[a] >= height[b]) {
        count++;
        bad[b] = 1;
      }
    }
  }
  cout << N - count << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  int N, M, a_i, b_i, a, b;
  int height[10000];
  int bad[10000] = {};
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> height[i];
  }
  int count = 0;
  for (int i = 0; i < M; i++) {
    cin >> a_i >> b_i;
    a = a_i - 1;
    b = b_i - 1;
    if (bad[a] == 0) {
      if (height[a] <= height[b]) {
        count++;
        bad[a] = 1;
      }
    }
    if (bad[b] == 0) {
      if (height[a] >= height[b]) {
        count++;
        bad[b] = 1;
      }
    }
  }
  cout << N - count << endl;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  rep(i, n) cin >> h.at(i);
  map<int, vector<int>> ab;

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

  ll ans = 0;

  rep(i, n) {
    bool check = true;
    for (auto p : ab[i]) {
      if (h.at(i) <= h.at(p))
        check = false;
    }
    if (check)
      ans++;
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  rep(i, n) cin >> h.at(i);
  vector<pair<ll, ll>> ab(0);
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    ab.push_back(make_pair(a - 1, b - 1));
    ab.push_back(make_pair(b - 1, a - 1));
  }

  sort(all(ab));

  ll flag = 0;

  ll ans = 0;

  rep(i, n) {
    bool check = true;
    while (ab.at(flag).first == i) {
      if (h.at(i) <= h.at(ab.at(flag).second)) {
        check = false;
      }
      flag++;
      if (flag == 2 * m)
        break;
    }
    if (check)
      ans++;
  }

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

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <ctype.h>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

long long h[100000];
int tou[100000];
int main() {
  int n, m;
  cin >> n >> m;
  int a, b;
  REP(i, n) tou[i] = 1;

  REP(i, n) { cin >> h[i]; }
  REP(i, m) {
    cin >> a >> b;
    if (h[a - 1] == h[b - 1]) {
      tou[b - 1] = 0;
      tou[a - 1] = 0;
    } else if (h[a - 1] > h[b - 1]) {
      tou[b - 1] = 0;
    } else if (h[a - 1] < h[b - 1]) {
      tou[a - 1] = 0;
    }
  }

  int ans = 0;

  REP(i, n) {

    if (tou[i] == 1) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <ctype.h>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, m;
  cin >> n >> m;
  long long h[m];
  int a, b;
  int tou[n];
  REP(i, n) tou[i] = 1;

  REP(i, n) { cin >> h[i]; }
  REP(i, m) {
    cin >> a >> b;
    if (h[a - 1] == h[b - 1]) {
      tou[b - 1] = 0;
      tou[a - 1] = 0;
    } else if (h[a - 1] > h[b - 1]) {
      tou[b - 1] = 0;
    } else if (h[a - 1] < h[b - 1]) {
      tou[a - 1] = 0;
    }
  }

  int ans = 0;

  REP(i, n) {

    if (tou[i] == 1) {
      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 endl "\\n"

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

  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  vector<set<int>> adj(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].insert(h[v]);
    adj[v].insert(h[u]);
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (adj[i].empty()) {
      ans++;
      continue;
    }
    auto it = adj[i].end();
    it--; // largest element
    ans += (h[i] > *it);
  }
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

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

typedef long long ll;
#define endl "\\n"

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

  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  vector<set<int>> adj(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].insert(h[v]);
    adj[v].insert(h[u]);
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    auto it = adj[i].end();
    it--; // largest element
    ans += (h[i] > *it);
  }
  cout << ans;
  return 0;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N), Ma(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  for (int i = 0; i < N; i++) {
    Ma.at(i) = 0;
  }
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    Ma.at(a - 1) = max(Ma.at(a - 1), H.at(b - 1));
    Ma.at(b - 1) = max(Ma.at(b - 1), H.at(a - 1));
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (H.at(i) > Ma.at(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 3) >= this->size() (which is 3)


Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N), Ma(M);
  for (int i = 1; i <= N; i++) {
    cin >> H.at(i);
    Ma.at(i) = 0;
  }
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    Ma.at(a) = max(Ma.at(a), H.at(b));
    Ma.at(b) = max(Ma.at(b), H.at(a));
  }
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (H.at(i) > Ma.at(i)) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll, ll>>
#define vvl vector<vector<ll>> // a(縦行,vector<ll>(横列));
#include <algorithm>           //__gcd(a,b)
#include <cstdlib>
#include <iostream>
#include <vector>
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const long long INF = 1LL << 60;

int main() {
  ll n, m;
  cin >> n >> m;
  vl h(n);
  rep(i, n) cin >> h[i];
  vl a(m), b(m);
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  ll sum = 0;

  vl ans(n);
  rep(i, n) ans[i] = 1;

  rep(i, m) {
    if (h[a[i]] < h[b[i]])
      ans[a[i]] = 0;
    if (h[a[i]] > h[b[i]])
      ans[b[i]] = 0;
    if (h[a[i]] == h[b[i]]) {
      ans[a[i]] = 0;
      ans[b[i]] = 0;
    }
  }

  rep(i, n) if (ans[i]) sum++;

  cout << sum << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll, ll>>
#define vvl vector<vector<ll>> // a(縦行,vector<ll>(横列));
#include <algorithm>           //__gcd(a,b)
#include <cstdlib>
#include <iostream>
#include <vector>
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const long long INF = 1LL << 60;

int main() {
  ll n, m;
  cin >> n >> m;
  vl h(n);
  rep(i, n) cin >> h[i];
  vl a(m), b(m);
  rep(i, m) cin >> a[i] >> b[i];
  ll sum = 0;

  vl ans(n);
  rep(i, n) ans[i] = 1;

  rep(i, m) {
    if (h[a[i]] < h[b[i]])
      ans[a[i]] = 0;
    if (h[a[i]] > h[b[i]])
      ans[b[i]] = 0;
    if (h[a[i]] == h[b[i]])
      ans[a[i]] = 0;
    ans[b[i]] = 0;
  }

  rep(i, n) if (ans[i]) sum++;

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

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

const ll INF = 1LL << 60;

vector<ll> G[100100];

int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> H(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &H[i]);
  }
  std::vector<long long> A(M);
  std::vector<long long> B(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
    A[i]--;
    B[i]--;
  }

  for (int i = 0; i < M; i++) {
    G[A[i]].push_back(H[B[i]]);
    G[B[i]].push_back(H[A[i]]);
  }

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    // cout << G[i].size() << endl;
    if (G[i].size() == 0) {
      ans++;
    } else {
      vector<ll> v = G[i];
      sort(v.rbegin(), v.rend());
      // cout << v[0] << endl;
      if (H[i] > v[0]) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

const ll INF = 1LL << 60;

vector<ll> G[10010];

int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> H(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &H[i]);
  }
  std::vector<long long> A(M);
  std::vector<long long> B(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
    A[i]--;
    B[i]--;
  }

  for (int i = 0; i < M; i++) {
    G[A[i]].push_back(H[B[i]]);
    G[B[i]].push_back(H[A[i]]);
  }

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    // cout << G[i].size() << endl;
    if (G[i].size() == 0) {
      ans++;
    } else {
      vector<ll> v = G[i];
      sort(v.rbegin(), v.rend());
      // cout << v[0] << endl;
      if (H[i] > v[0]) {
        ans++;
      }
      // for (int j = 0; j < G[i].size(); j++) {
      //     cout << G[i][j] << " ";
      // }
      // cout << endl;
    }
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
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<int> ab(2 * m);
  for (int i = 0; i < 2 * m; i++) {
    cin >> ab[i];
  }
  // ok
  // goodはよい展望台のこと
  vector<int> good(n);
  for (int i = 0; i < n; i++) {
    good[i] = 1;
  }
  // iはi番目の展望台の探索
  for (int i = 0; i < 2 * m; i += 2) {
    if (good[ab[i] - 1] == 0 && good[ab[i + 1] - 1] == 0) {
      continue;
    }
    if (h[ab[i] - 1] > h[ab[i + 1] - 1]) {
      good[ab[i + 1] - 1] = 0;
    } else if (h[ab[i] - 1] < h[ab[i + 1] - 1]) {
      good[ab[i] - 1] = 0;
    } else {
      good[ab[i] - 1] = 0;
      good[ab[i + 1] - 1] = 0;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += good[i];
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
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<int> ab(2 * m);
  for (int i = 0; i < 2 * m; i++) {
    cin >> ab[i];
  }
  // ok
  // goodはよい展望台のこと
  vector<int> good(n);
  for (int i = 0; i < n; i++) {
    good[i] = 1;
  }
  // iはi番目の展望台の探索
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2 * m; j += 2) {
      if (i == ab[j] - 1) {
        if (h[ab[j] - 1] < h[ab[j + 1] - 1] ||
            h[ab[j] - 1] == h[ab[j + 1] - 1]) {
          good[i] = 0;
        }
        if (h[ab[j] - 1] > h[ab[j + 1] - 1] ||
            h[ab[j] - 1] == h[ab[j + 1] - 1]) {
          good[ab[j + 1] - 1] = 0;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += good[i];
  }
  cout << ans << endl;
}
Problem p02689 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define REP3(i, x, n) for (int i = x; i > (n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n), end(n)
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
const long long INF = numeric_limits<long long>::max();
int main() {
  int n, m, h[114514], ma[114514];
  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: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define REP3(i, x, n) for (int i = x; i > (n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n), end(n)
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
const long long INF = numeric_limits<long long>::max();
int main() {
  int n, m, h[114514810], ma[114514810];
  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

//
// AtCoder Beginner Contest 166
// C - Peaks
//

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define reAll(x) (x).rbegin(), (x).rend()

using ll = long long;

const double PI = 3.14159265358979323846;
const int MOD = 1000000007;

ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main() {
  int n, m;

  cin >> n >> m;

  ll h[n];
  bool good[n];
  rep(i, n) {
    cin >> h[i];
    good[i] = true;
  }

  int a[m], b[m];

  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }

  int ans = 0;

  rep(j, m) {
    if (h[a[j]] <= h[b[j]]) {
      good[a[j]] = false;
    }
    if (h[a[j]] >= h[b[j]]) {
      good[b[j]] = false;
    }
  }

  rep(i, n) {
    if (good[i])
      ans++;
    // cout << good[i] << endl;
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

//
// AtCoder Beginner Contest 166
// C - Peaks
//

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define reAll(x) (x).rbegin(), (x).rend()

using ll = long long;

const double PI = 3.14159265358979323846;
const int MOD = 1000000007;

ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main() {
  int n, m;

  cin >> n >> m;

  ll h[n];
  bool good[n];
  rep(i, n) {
    cin >> h[i];
    good[i] = true;
  }

  int a[m], b[m];

  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }

  int ans = 0;
  rep(i, n) {
    rep(j, m) {
      if (a[j] == i) {
        if (h[a[j]] <= h[b[j]]) {
          good[i] = false;
          break;
        }
      }
      if (b[j] == i) {
        if (h[a[j]] >= h[b[j]]) {
          good[i] = false;
          break;
        }
      }
    }
  }
  rep(i, n) {
    if (good[i])
      ans++;
    // cout << good[i] << endl;
  }

  cout << ans << endl;

  return 0;
}