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

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...)                                                              \\
  (cerr << #__VA_ARGS__ << " = " << (DUMP(), __VA_ARGS__).str() << " ["        \\
        << __LINE__ << "]" << endl)
struct DUMP : ostringstream {
  template <class T> DUMP &operator,(const T &t) {
    if (this->tellp())
      *this << ", ";
    *this << t;
    return *this;
  }
};
#else
#define dump(...)
#endif
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
  rep(i, v.size()) os << v[i] << (i + 1 == v.size() ? "" : " ");
  return os;
}

template <class T, class U> ostream &operator<<(ostream &os, pair<T, U> p) {
  return os << "(" << p.first << " " << p.second << ")";
}

int x1[100010];
int x2[100010];
int y1_[100010];
int y2[100010];

int main() {
  int N, W, H;
  while (cin >> N >> W >> H && N) {
    rep(i, N) {
      int x, y, w;
      cin >> x >> y >> w;
      tie(x1[i], x2[i]) = mp(max(0, x - w), min(W, x + w));
      tie(y1_[i], y2[i]) = mp(max(0, y - w), min(H, y + w));
    }

    auto chk = [N](int *l, int *r, int ww) {
      static int sum[100010];
      memset(sum, 0, sizeof(sum));
      rep(i, N) {
        sum[l[i]]++;
        sum[r[i]]--;
      }
      bool ok = true;
      int t = 0;
      rep(i, ww) {
        t += sum[i];
        if (t == 0)
          ok = false;
      }
      return ok;
    };

    bool flg = chk(x1, x2, W) || chk(y1_, y2, H);
    puts(flg ? "Yes" : "No");
  }
}

Error: 0

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...)                                                              \\
  (cerr << #__VA_ARGS__ << " = " << (DUMP(), __VA_ARGS__).str() << " ["        \\
        << __LINE__ << "]" << endl)
struct DUMP : ostringstream {
  template <class T> DUMP &operator,(const T &t) {
    if (this->tellp())
      *this << ", ";
    *this << t;
    return *this;
  }
};
#else
#define dump(...)
#endif
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
  rep(i, v.size()) os << v[i] << (i + 1 == v.size() ? "" : " ");
  return os;
}

template <class T, class U> ostream &operator<<(ostream &os, pair<T, U> p) {
  return os << "(" << p.first << " " << p.second << ")";
}

int sum[100010];

int main() {
  int N, W, H;
  while (cin >> N >> W >> H) {
    vector<pair<int, int>> xx(N), yy(N);
    rep(i, N) {
      int x, y, w;
      cin >> x >> y >> w;
      xx[i] = mp(max(0, x - w), min(W, x + w));
      yy[i] = mp(max(0, y - w), min(W, y + w));
    }

    bool flg = false;
    for (auto &ps : {xx, yy}) {
      memset(sum, 0, sizeof(sum));
      rep(i, N) {
        int l, r;
        tie(l, r) = ps[i];
        sum[l]++;
        sum[r + 1]--;
      }
      loop(i, 1, W + 1) { sum[i] += sum[i - 1]; }
      bool ok = true;
      rep(i, W + 1) {
        if (sum[i] == 0) {
          ok = false;
        }
      }
      if (ok)
        flg = true;
    }
    puts(flg ? "Yes" : "No");
  }
}