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

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define LP(i, n) for (int i = 0; i < n; i++)
#define Mset(x, v) memset(x, v, sizeof(x))
#define INF INT_MAX

using namespace std;
using LL = long long;

int X[100005], Y[100005];

int main() {
  int n, W, H, x, y, w, ax = 1, ay = 1, xs = 0, ys = 0;
  cin >> n >> W >> H;
  for (int i = 0; i < n; i++) {
    cin >> x >> y >> w;
    X[max(0, x - w)]++;
    X[min(x + w, W)]--;
    Y[max(0, y - w)]++;
    Y[min(y + w, H)]--;
  }
  for (int i = 0; i < W; i++) {
    xs += X[i];
    if (xs <= 0)
      ax = 0;
  }
  for (int i = 0; i < H; i++) {
    ys += Y[i];
    if (ys <= 0)
      ay = 0;
  }
  if (ax || ay)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define LP(i, n) for (int i = 0; i < n; i++)
#define Mset(x, v) memset(x, v, sizeof(x))
#define INF INT_MAX

using namespace std;
using LL = long long;

int X[100005], Y[100005];

int main() {
  int n, W, H, x, y, w, ax = 1, ay = 1;
  cin >> n >> W >> H;
  for (int i = 0; i < n; i++) {
    cin >> x >> y >> w;
    for (int p = x - w; p < x + w; p++) {
      if (p < 0 || p >= W)
        continue;
      X[p]++;
    }
    for (int p = y - w; p < y + w; p++) {
      if (p < 0 || p >= H)
        continue;
      Y[p]++;
    }
  }
  for (int i = 0; i < W; i++)
    if (X[i] == 0)
      ax = 0;
  for (int i = 0; i < H; i++)
    if (Y[i] == 0)
      ay = 0;
  if (ax || ay)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p01712 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int mx[100020], my[100020];
int main() {
  int n, h, w;
  cin >> n >> w >> h;

  while (n--) {
    int x, y, c;
    cin >> x >> y >> c;
    mx[max(0, x - c)]++;
    mx[min(w + 1, x + c)]--;
    my[max(0, y - c)]++;
    my[min(h + 1, y + c)]--;
  }
  int ans = 0;
  for (int i = 0; i < w - 1; i++)
    mx[i + 1] += mx[i];
  for (int i = 0; i < h - 1; i++)
    my[i + 1] += my[i];
  for (int i = 0; i < w; i++)
    if (mx[i] == 0) {
      ans++;
      break;
    }
  for (int i = 0; i < h; i++)
    if (my[i] == 0) {
      ans++;
      break;
    }

  if (ans != 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int mx[10020], my[10020];
int main() {
  int n, h, w;
  cin >> n >> w >> h;

  while (n--) {
    int x, y, c;
    cin >> x >> y >> c;
    mx[max(0, x - c)]++;
    mx[min(w + 1, x + c)]--;
    my[max(0, y - c)]++;
    my[min(h + 1, y + c)]--;
  }
  int ans = 0;
  for (int i = 0; i < w - 1; i++)
    mx[i + 1] += mx[i];
  for (int i = 0; i < h - 1; i++)
    my[i + 1] += my[i];
  for (int i = 0; i < w; i++)
    if (mx[i] == 0) {
      ans++;
      break;
    }
  for (int i = 0; i < h; i++)
    if (my[i] == 0) {
      ans++;
      break;
    }

  if (ans != 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p01712 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int x[110000] = {}, y[110000] = {};

int main() {
  int n, W, H;
  scanf("%d%d%d", &n, &W, &H);
  for (int i = 0; i < n; i++) {
    int xw, yw, w;
    scanf("%d%d%d", &xw, &yw, &w);
    x[max(0, xw - w)] = max(x[max(0, xw - w)], min(xw + w, W));
    y[max(0, yw - w)] = max(y[max(0, yw - w)], min(yw + w, H));
  }
  bool xyes = false;
  int mx = x[0];
  for (int i = 0; i <= mx; i++) {
    mx = max(mx, x[i]);
    if (mx >= W) {
      xyes = true;
      break;
    }
  }
  bool yyes = false;
  mx = y[0];
  for (int i = 0; i <= mx; i++) {
    mx = max(mx, y[i]);
    if (mx >= H) {
      yyes = true;
      break;
    }
  }

  bool yes = true;
  if (!xyes && !yyes) {
    yes = false;
  }
  if (yes) {
    printf("Yes\\n");
  } else {
    printf("No\\n");
  }

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n, W, H;
  cin >> n >> W >> H;
  bool x[110000] = {}, y[110000] = {};
  for (int i = 0; i < n; i++) {
    int xw, yw, w;
    cin >> xw >> yw >> w;
    for (int t = max(0, xw - w); t < min(xw + w, W); t++) {
      x[t] = true;
    }
    for (int t = max(0, yw - w); t < min(yw + w, H); t++) {
      y[t] = true;
    }
  }
  bool xyes = true;
  for (int i = 0; i < W; i++) {
    if (!x[i]) {
      xyes = false;
      break;
    }
  }
  bool yyes = true;
  for (int i = 0; i < H; i++) {
    if (!y[i]) {
      yyes = false;
      break;
    }
  }
  bool yes = true;
  if (!xyes && !yyes) {
    yes = false;
  }
  cout << (yes ? "Yes" : "No") << endl;

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

#include <bits/stdc++.h>
#define r(i, a, n) for (int i = a; i < n; i++)
using namespace std;
int x[191919], y[191919];
int main() {
  int n, a, b, d, e, f, p = 0;
  cin >> n >> a >> b;
  r(i, 0, n) {
    cin >> d >> e >> f;
    y[max(0, e - f)]--;
    y[min(b, e + f)]++;
    x[max(0, d - f)]--;
    x[min(a, d + f)]++;
  }
  r(i, 1, b + 1) y[i] += y[i - 1];
  r(i, 1, a + 1) x[i] += x[i - 1];
  r(i, 0, b) if (y[i] == 0) {
    p++;
    break;
  }
  r(i, 0, a) if (x[i] == 0) {
    p++;
    break;
  }
  if (p == 2)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define r(i, a, n) for (int i = a; i < n; i++)
using namespace std;
int x[191919], y[191919];
int main() {
  int n, a, b, d, e, f, p = 0;
  cin >> n >> a >> b;
  r(i, 0, n) {
    cin >> d >> e >> f;
    y[max(0, e - f)]--;
    y[e + f]++;
    x[max(0, d - f)]--;
    x[d + f]++;
  }
  r(i, 1, b + 1) y[i] += y[i - 1];
  r(i, 1, a + 1) x[i] += x[i - 1];
  r(i, 0, b) if (y[i] == 0) {
    p++;
    break;
  }
  r(i, 0, a) if (x[i] == 0) {
    p++;
    break;
  }
  if (p == 2)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}
Problem p01712 (C++) — buggy submission, verdict: Time Limit Exceeded

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

struct Xfi {
  bool operator<(const Xfi &xfi) const { return x - w < xfi.x - xfi.w; }
  int x, w;
};

struct Yfi {
  bool operator<(const Yfi &yfi) const { return y - w < yfi.y - yfi.w; }
  int y, w;
};

int main() {
  int N, W, H;
  cin >> N >> W >> H;

  vector<Xfi> xfis(N);
  vector<Yfi> yfis(N);

  for (int i = 0; i < N; i++) {
    int x, y, w;
    cin >> x >> y >> w;

    xfis[i].x = x;
    yfis[i].y = y;
    xfis[i].w = yfis[i].w = w;
  }

  bool flg = false;

  sort(xfis.begin(), xfis.end());
  int x = 0;
  for (int i = 0; i < N; i++) {
    if (xfis[i].x - xfis[i].w > x) {
      flg = true;
      break;
    }
    x = max(xfis[i].x + xfis[i].w, x);
  }
  flg = x < W || flg;

  if (flg) {
    flg = false;
    sort(yfis.begin(), yfis.end());
    int y = 0;
    for (int i = 0; i < N; i++) {
      if (yfis[i].y - yfis[i].w > y) {
        flg = true;
        break;
      }
      y = max(yfis[i].y + yfis[i].w, y);
    }
    flg = y < H || flg;
  }

  cout << (!flg ? "Yes" : "No") << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int N, W, H;
  cin >> N >> W >> H;

  vector<bool> xFlgs(W), yFlgs(H);
  fill(xFlgs.begin(), xFlgs.end(), false);
  fill(yFlgs.begin(), yFlgs.end(), false);

  for (int i = 0; i < N; i++) {
    int x, y, w;
    cin >> x >> y >> w;

    for (int j = max(x - w, 0); j < min(x + w, W); j++) {
      xFlgs[j] = true;
    }

    for (int j = max(y - w, 0); j < min(y + w, H); j++) {
      yFlgs[j] = true;
    }
  }

  bool flg = false;
  for (int x = 0; x < W; x++) {
    if (!xFlgs[x]) {
      flg = true;
      break;
    }
  }
  if (flg) {
    flg = false;
    for (int y = 0; y < H; y++) {
      if (!yFlgs[y]) {
        flg = true;
        break;
      }
    }
  }

  cout << (!flg ? "Yes" : "No") << endl;

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

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, w, h;
  int ah[114514] = {}, aw[114514] = {};
  cin >> n >> w >> h;
  for (int i = 0; i < n; i++) {
    int x, y, wi;
    cin >> x >> y >> wi;
    aw[max(0, x - wi)]++;
    aw[min(w, x + wi)]--;
    ah[max(0, y - wi)]++;
    ah[min(w, y + wi)]--;
  }
  bool b1 = true;
  int v = 0;
  for (int i = 0; i < w; i++) {
    v += aw[i];
    if (v <= 0)
      b1 = false;
  }
  bool b2 = true;
  v = 0;
  for (int i = 0; i < h; i++) {
    v += ah[i];
    if (v <= 0)
      b2 = false;
  }
  cout << (b1 || b2 ? "Yes" : "No") << endl;
  char c;
  cin >> c;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  bool koto[10010][10010];
  int h, n, w;
  cin >> n >> w >> h;
  for (int i = 0; i < w + 1; i++)
    for (int j = 0; j < h + 1; j++)
      koto[w][h] = false;
  for (int i = 0; i < n; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    for (int j = b - c; j < b + c; j++) {
      for (int k = 0; k < w + 1; k++) {
        koto[k][j] = true;
      }
    }
    for (int j = a - c; j < a + c; j++) {
      for (int k = 0; k < h + 1; k++) {
        koto[j][k] = true;
      }
    }
  }
  for (int i = 0; i < w + 1; i++)
    for (int j = 0; j < h + 1; j++)
      if (!koto[i][j])
        goto Exit;
  cout << "Yes\\n";
  return 0;
Exit:
  cout << "No\\n";
  return 0;
}
Problem p01712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

const long N = 100000;

int main() {
  long n, w, h;
  long tate[N + 1], yoko[N + 1];

  memset(tate, 0, sizeof(tate));
  memset(yoko, 0, sizeof(yoko));

  scanf(" %ld %ld %ld", &n, &w, &h);

  for (long i = 0; i < n; ++i) {
    long x, y, z;
    scanf(" %ld %ld %ld", &x, &y, &z);

    // tate direct
    long ta = x - z + 1, tb = x + z;
    if (ta < 1)
      ta = 1;
    if (tb > w)
      tb = w;
    tate[ta]++;
    tate[tb + 1]--;

    // yoko direct
    long ya = y - z + 1, yb = y + z;
    if (ya < 1)
      ya = 1;
    if (yb > h)
      yb = h;
    yoko[ya]++;
    yoko[yb + 1]--;
  }

  for (long i = 0; i <= w; ++i)
    tate[i + 1] += tate[i];
  for (long i = 0; i <= h; ++i)
    yoko[i + 1] += yoko[i];

  /*
    for(long i=0; i<=w; ++i) printf("tate[%ld]=%d\\n", i, tate[i]);
    for(long i=0; i<=h; ++i) printf("yoko[%ld]=%d\\n", i, yoko[i]);
  */

  bool ans = true;
  for (long i = 1; i <= w; ++i) {
    if (tate[i] <= 0) {
      ans = false;
      break;
    }
  }

  if (!ans) {
    ans = true;
    for (long i = 1; i <= h; ++i) {
      if (yoko[i] <= 0) {
        ans = false;
        break;
      }
    }
  }
  if (ans)
    printf("Yes\\n");
  else
    printf("No\\n");
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int tbl[100010];
bool chk(int w, vector<P> c) {
  int n = c.size();
  memset(tbl, 0, sizeof(tbl));
  for (int i = 0; i < n; ++i) {
    tbl[c[i].first]++;
    tbl[c[i].second + 1]--;
  }
  int st = 0;
  for (int i = 0; i <= w; ++i) {
    st += tbl[i];
    if (st <= 0)
      return false;
  }
  return true;
}

int main() {
  int n, w, h;
  while (scanf("%d%d%d", &n, &w, &h), n || w || h) {
    vector<P> rng1, rng2;
    for (int i = 0; i < n; ++i) {
      int x, y, d;
      scanf("%d%d%d", &x, &y, &d);
      rng1.push_back(P(max(0, x - d), min(w, x + d)));
      rng2.push_back(P(max(0, y - d), min(h, y + d)));
    }
    if (chk(w, rng1) || chk(h, rng2))
      printf("Yes\\n");
    else
      printf("No\\n");
  }
  return 0;
}
Problem p01712 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n, w, h;
  cin >> n >> w >> h;
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      qx, qy;
  for (int i = 0; i < n; ++i) {
    int cx, cy, cw;
    cin >> cx >> cy >> cw;
    qx.push(make_pair(cx, cw));
    qy.push(make_pair(cy, cw));
  }
  int flgx = 0;
  int flgy = 0;
  for (int i = 0; i < w; ++i) {
    for (; qx.size() != 0; qx.pop())
      if (i >= qx.top().first - qx.top().second &&
          i < qx.top().first + qx.top().second) {
        break;
      }
    if (qx.size() == 0) {
      flgx = 1;
      break;
    }
  }
  for (int i = 0; i < h; ++i) {
    for (; qy.size() != 0; qy.pop())
      if (i >= qy.top().first - qy.top().second &&
          i < qy.top().first + qy.top().second) {
        break;
      }
    if (qy.size() == 0) {
      flgy = 1;
      break;
    }
  }
  if (flgx == 1 && flgy == 1) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n, w, h;
  cin >> n >> w >> h;
  int x[100000] = {};
  int y[100000] = {};
  for (int i = 0; i < n; ++i) {
    int cx, cy, cw;
    cin >> cx >> cy >> cw;
    int jmin, jmax;
    jmin = max(cx - cw, 0);
    jmax = min(cx + cw, w + 1);
    for (int j = jmin; j < jmax; ++j) {
      x[j] |= 1;
    }
    jmin = max(cy - cw, 0);
    jmax = min(cy + cw, h + 1);
    for (int j = jmin; j < jmax; ++j) {
      y[j] |= 1;
    }
  }
  int flgx = 0;
  int flgy = 0;
  for (int i = 0; i < w; ++i) {
    if (x[i] == 0) {
      flgx = 1;
      break;
    }
  }
  for (int i = 0; i < h; ++i) {
    if (y[i] == 0) {
      flgy = 1;
      break;
    }
  }
  if (flgx == 1 && flgy == 1) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}
Problem p01712 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define MOD 1000000007
#define allof(a) (a).begin(), (a).end()
using namespace std;

const double EPS = 1e-9;
const int INF = 1L << 30;
vector<int> dx = {0, 1, 0, -1};
const int dy[4] = {-1, 0, 1, 0};

bool in_range(int x, int lb, int ub) { return lb <= x and x < ub; }
bool in_range(int x, int y, int W, int H) {
  return in_range(x, 0, W) and in_range(y, 0, H);
}
void modAdd(int &a, int b, int mod) { a = (a + b) % MOD; }
template <typename T> void maxUpdate(T &a, T b) { a = max(a, b); }

int main() {

  int N, W, H;
  cin >> N >> W >> H;

  vector<int> X(W + 1);
  vector<int> Y(H + 1);
  for (int i = 0; i < N; i++) {
    int x, y, w;
    cin >> x >> y >> w;
    X[max(0, x - w)]++, X[min(W, x + w)]--;
    Y[max(0, y - w)]++, Y[min(H, y + w)]--;
  }

  int x_sum = 0;
  bool x_flg = false;
  for (int i = 0; i < W; i++) {
    x_sum += X[i];
    if (x_sum <= 0) {
      x_flg = true;
    }
  }
  int y_sum = 0;
  bool y_flg = false;
  for (int i = 0; i < H; i++) {
    y_sum += Y[i];
    if (y_sum <= 0) {
      y_flg = true;
    }
  }
  if (x_flg and y_flg) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define MOD 1000000007
#define allof(a) (a).begin(), (a).end()
using namespace std;

const double EPS = 1e-9;
const int INF = 1L << 30;
vector<int> dx = {0, 1, 0, -1};
const int dy[4] = {-1, 0, 1, 0};

bool in_range(int x, int lb, int ub) { return lb <= x and x < ub; }
bool in_range(int x, int y, int W, int H) {
  return in_range(x, 0, W) and in_range(y, 0, H);
}
void modAdd(int &a, int b, int mod) { a = (a + b) % MOD; }
template <typename T> void maxUpdate(T &a, T b) { a = max(a, b); }

int main() {

  int N, W, H;
  cin >> N >> W >> H;

  vector<int> X(W);
  vector<int> Y(H);
  for (int i = 0; i < N; i++) {
    int x, y, w;
    cin >> x >> y >> w;
    X[max(0, x - w)]++, X[x + w]--;
    Y[max(0, y - w)]++, Y[y + w]--;
  }

  int x_sum = 0;
  bool x_flg = false;
  for (int i = 0; i < W; i++) {
    x_sum += X[i];
    if (x_sum <= 0) {
      x_flg = true;
    }
  }
  int y_sum = 0;
  bool y_flg = false;
  for (int i = 0; i < H; i++) {
    y_sum += Y[i];
    if (y_sum <= 0) {
      y_flg = true;
    }
  }
  if (x_flg and y_flg) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

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

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

size_t to_index(int x, int y, int w) { return y * w + x; }

bool are_all_true(std::vector<bool> &v) {
  return std::all_of(v.begin(), v.end(), [](bool x) { return x; });
}

int main() {
  int n, w, h;
  std::cin >> n >> w >> h;

  std::vector<bool> columns(w, false);
  std::vector<bool> rows(h, false);

  for (int i = 0; i < n; i++) {
    int x, y, kotod;
    std::cin >> x >> y >> kotod;

    std::fill(columns.begin() + std::max(0, x - kotod),
              columns.begin() + std::min(w, x + kotod), true);
    std::fill(rows.begin() + std::max(0, y - kotod),
              rows.begin() + std::min(h, y + kotod), true);
  }

  std::cout << (are_all_true(columns) || are_all_true(rows) ? "Yes\\n" : "No\\n");
}

Error: MLE

Fixed submission:

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

size_t to_index(int x, int y, int w) { return y * w + x; }

int main() {
  int n, w, h;
  std::cin >> n >> w >> h;

  std::vector<bool> map((size_t)w * h, false);

  for (int i = 0; i < n; i++) {
    int x, y, kotod;
    std::cin >> x >> y >> kotod;

    for (int j = std::max(0, y - kotod); j < std::min(h, y + kotod); j++) {
      for (int k = 0; k < w; k++) {
        map[to_index(k, j, w)] = true;
      }
    }

    for (int j = std::max(0, x - kotod); j < std::min(w, x + kotod); j++) {
      for (int k = 0; k < h; k++) {
        map[to_index(j, k, w)] = true;
      }
    }
  }

  std::cout << (std::all_of(map.begin(), map.end(), [](bool x) { return x; })
                    ? "Yes\\n"
                    : "No\\n");
}
Problem p01712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for (LL i = 0; i < n; ++i)
#define FOR(i, a, n) for (LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

// #define int long long

/*************** using variables ***************/
int N, W, H;
vector<int> x, y, w;
int imosw[100005];
int imosh[100005];
/**********************************************/

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

  cin >> N >> W >> H;
  x.resize(N);
  y.resize(N);
  w.resize(N);
  REP(i, N) cin >> x[i] >> y[i] >> w[i];

  REP(i, N) {
    imosw[max(x[i] - w[i], 0)]++;
    imosw[min(x[i] + w[i], W)]--;

    imosh[max(y[i] - w[i], 0)]++;
    imosh[min(y[i] + w[i], H)]--;
  }

  bool flag1 = imosw[0] != 0;
  bool flag2 = imosh[0] != 0;
  FOR(i, 1, W) {
    imosw[i] += imosw[i - 1];
    flag1 &= imosw[i] != 0;
  }
  FOR(i, 1, H) {
    imosh[i] += imosh[i - 1];
    flag2 &= imosh[i] != 0;
  }
  cout << (flag1 || flag2 ? "Yes" : "No") << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for (LL i = 0; i < n; ++i)
#define FOR(i, a, n) for (LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

// #define int long long

/*************** using variables ***************/
int N, W, H;
vector<int> x, y, w;
int imosw[100005];
int imosh[100005];
/**********************************************/

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

  cin >> N >> W >> H;
  x.resize(N);
  y.resize(N);
  w.resize(N);
  REP(i, N) cin >> x[i] >> y[i] >> w[i];

  REP(i, N) {
    imosw[max(x[i] - w[i], 0)]++;
    imosw[min(x[i] + w[i], W)]--;

    imosh[max(y[i] - w[i], 0)]++;
    imosh[min(y[i] + w[i], H)]--;
  }

  bool flag = true;
  FOR(i, 1, W) { imosw[i] += imosw[i - 1]; }
  FOR(i, 1, H) { imosh[i] += imosh[i - 1]; }
  REP(i, H) REP(j, W) {
    flag &= imosh[i] != 0 || imosw[j] != 0;
    // cout << j << " " << i << " " << imosw[j] << " " << imosh[i] << endl;
  }
  cout << (flag ? "Yes" : "No") << endl;
}
Problem p01712 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
#define Max 100000
using namespace std;
int main(void) {
  int n, w, h;
  cin >> n >> w >> h;
  vector<int> x(n), y(n), r(n);
  vector<int> xl(w + 1, 0), yl(h + 1, 0);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> r[i];
    xl[max(0, x[i] - r[i])]++;
    xl[min(w, x[i] + r[i])]--;
    yl[max(0, y[i] - r[i])]++;
    yl[min(h, y[i] + r[i])]--;
  }
  bool ansx = true, ansy = true;
  for (int i = 0; i < w; i++) {
    xl[i + 1] += xl[i];
  }
  for (int i = 0; i < h; i++) {
    yl[i + 1] += yl[i];
  }
  for (int i = 0; i < w; i++) {
    if (xl[i] == 0)
      ansx = false;
  }
  for (int i = 0; i < h; i++) {
    if (yl[i] == 0)
      ansy = false;
  }
  if (ansx || ansy) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
#define Max 100000
using namespace std;
int main(void) {
  int n, w, h;
  cin >> n >> w >> h;
  vector<int> x(n), y(n), r(n);
  vector<int> xl(w + 1, 0), yl(h + 1, 0);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> r[i];
    xl[max(0, x[i] - r[i])]++;
    xl[min(w, x[i] + r[i])]--;
    yl[max(0, y[i] - r[i])]++;
    yl[min(h, y[i] + r[i])]--;
  }
  bool ansx = true, ansy = true;
  for (int i = 0; i < w + 1; i++) {
    xl[i + 1] += xl[i];
  }
  for (int i = 0; i < w; i++) {
    yl[i + 1] += yl[i];
  }
  for (int i = 0; i < w; i++) {
    if (xl[i] == 0)
      ansx = false;
  }
  for (int i = 0; i < h; i++) {
    if (yl[i] == 0)
      ansy = false;
  }
  if (ansx || ansy) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}