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

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

int main() {

  int n, w, h;
  int imosx[100003] = {0}, imosy[100003] = {0};

  cin >> n >> w >> h;
  for (int i = 0; i < n; i++) {
    int x, y, r;
    cin >> x >> y >> r;
    imosx[max(0, x - r)]++, imosx[min(w, x + r)]--;
    imosy[max(0, y - r)]++, imosy[min(h, y + r)]--;
  }

  for (int i = 1; i <= h; i++)
    imosy[i] += imosy[i - 1];
  for (int i = 1; i <= w; i++)
    imosx[i] += imosx[i - 1];

  bool ret = *min_element(imosx, imosx + w);
  ret = ret || *min_element(imosy, imosy + h);

  cout << (ret ? "Yes" : "No") << endl;
}


Error: TLE

Fixed submission:

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

int main() {

  int n, w, h;
  int imosx[100003] = {0}, imosy[100003] = {0};

  cin >> n >> w >> h;
  for (int i = 0; i < n; i++) {
    int x, y, r;
    cin >> x >> y >> r;
    imosx[max(1, x - r)]++, imosx[min(w + 1, x + r + 1)]--;
    imosy[max(1, y - r)]++, imosy[min(h + 1, y + r + 1)]--;
  }

  for (int i = 1; i <= h; i++)
    imosy[i] += imosy[i - 1];
  for (int i = 1; i <= w; i++)
    imosx[i] += imosx[i - 1];

  bool ret = true;
  for (int i = 1; i <= h; i++) {
    if (!imosy[i] && !(*min_element(imosx + 1, imosx + w + 1))) {
      ret = false;
    }
  }
  cout << (ret ? "Yes" : "No") << endl;
}
Problem p01712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef pair<int, int> i_i;
int main() {
  int n, w, h;
  int i, j, k;
  int x, y, r;
  vector<i_i> vx;
  vector<i_i> vy;
  i_i a;
  cin >> n >> w >> h;
  for (i = 0; i < n; i++) {
    cin >> x >> y >> r;
    a.first = x - r;
    a.second = x + r;
    vx.push_back(a);
    a.first = y - r;
    a.second = y + r;
    vy.push_back(a);
  }
  // cout << vx.size() << vy.size();
  sort(vx.begin(), vx.end());
  sort(vy.begin(), vy.end());
  int f = 0;
  int fi = vx[0].first, se = vx[0].second;
  // cout << fi;
  if (fi > 0) {
    f = 1;
  } else {
    for (i = 0; i < vx.size(); i++) {
      fi = vx[i].first;
      if (fi > se) {
        f = 1;
        break;
      }
      se = max(se, vx[i].second);
    }
  }
  // cout << se << endl;
  if (se < w)
    f = 1;
  if (f == 0) {
    cout << "Yes" << endl;
  } else {
    f = 0;
    fi = vy[0].first;
    se = vy[0].second;
    // cout << fi;
    if (fi > 0)
      f = 1;
    else
      for (i = 0; i < vy.size(); i++) {
        fi = vy[i].first;
        if (fi > se) {
          f = 1;
          break;
        }
        se = max(se, vy[i].second);
      }
    // cout << se << endl;
    if (se < h)
      f = 1;
    if (f == 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, w, h;
  int i, j, k;
  int mx[100001] = {};
  int my[100001] = {};
  cin >> n >> w >> h;
  int x, y, r;
  int a, b;
  int f = 0, f1 = 0;
  for (i = 0; i < n; i++) {
    cin >> x >> y >> r;
    a = x - r;
    b = x + r;
    if (a < 0)
      a = 0;
    if (b > w)
      b = w;
    fill(mx + a, mx + b, 1);
    a = y - r;
    b = y + r;
    if (a < 0)
      a = 0;
    if (b > h)
      b = h;
    fill(my + a, my + b, 1);
    /*
    for(j=x-r;j<=x+r-1;j++){
      if(j<0) j=0;
      if(j>=w) break;
      mx[j]=1;
    }
    for(j=y-r;j<=y+r-1;j++){
      if(j<0) j=0;
      if(j>=h) break;
      my[j]=1;
    }
    */
    f = 0;
    for (j = 0; j < w; j++) {
      if (mx[j] == 0) {
        f = 1;
      }
    }

    if (f == 0) {
      cout << "Yes" << endl;
      f1 = 1;
      break;
    }

    f = 0;
    for (j = 0; j < h; j++) {
      if (my[j] == 0) {
        f = 1;
      }
    }

    if (f == 0) {
      cout << "Yes" << endl;
      f1 = 1;
      break;
    }
  }
  // cout << f1 << endl;
  if (f1 == 0) {
    f = 0;
    for (i = 0; i < w; i++) {
      // cout << mx[i];
      if (mx[i] == 0) {
        f = 1;
        // break;
        // cout << i;
      }
    }
    // cout<< endl;
    if (f == 0)
      cout << "Yes" << endl;
    else {
      f = 0;
      for (i = 0; i < h; i++) {
        // cout << my[i];
        if (my[i] == 0) {
          f = 1;
          // break;
        }
      }
      if (f == 0)
        cout << "Yes" << endl;
      else
        cout << "No" << endl;
    }
  }
}
Problem p01712 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
// #define int long long

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

#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#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};

/*************** using variables **************/
int N, W, H;
vector<int> x, y, w;
vector<int> imosx, imosy;
/**********************************************/

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];

  imosx.assign(W + 2, 0);
  imosy.assign(H + 2, 0);
  REP(i, N) {
    imosx[max(x[i] - w[i], 0)]++;
    imosx[min(x[i] + w[i], W + 1)]--;
    imosy[max(y[i] - w[i], 0)]++;
    imosy[min(y[i] + w[i], H + 1)]--;
  }

  REP(i, W) { imosx[i + 1] += imosx[i]; }
  REP(i, H) { imosy[i + 1] += imosy[i]; }
  bool flag1 = true, flag2 = true;
  REP(i, W) if (imosx[i] <= 0) flag1 = false;
  REP(i, H) if (imosy[i] <= 0) flag2 = false;

  if (flag1 || flag2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
// #define int long long

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

#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#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};

/*************** using variables **************/
int N, W, H;
vector<int> x, y, w;
vector<int> imosx, imosy;
/**********************************************/

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];

  imosx.assign(W + 2, 0);
  imosy.assign(H + 2, 0);
  REP(i, N) {
    imosx[max(x[i] - w[i], 0)]++;
    imosx[min(x[i] + w[i], W + 2)]--;
    imosy[max(y[i] - w[i], 0)]++;
    imosy[min(y[i] + w[i], H + 2)]--;
  }

  REP(i, W) { imosx[i + 1] += imosx[i]; }
  REP(i, H) { imosy[i + 1] += imosy[i]; }
  bool flag1 = true, flag2 = true;
  REP(i, W) if (imosx[i] <= 0) flag1 = false;
  REP(i, H) if (imosy[i] <= 0) flag2 = false;

  if (flag1 || flag2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p01712 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main() {
  int N, W, H, x, y, w;
  cin >> N >> W >> H;
  vector<int> xvect(W + 2, 0), yvect(H + 2, 0);
  bool ans = true;
  for (int i = 0; i < N; i++) {
    cin >> x >> y >> w;
    xvect[max(x - w, 0)]++;
    xvect[min(x + w, W + 1)]--;
    yvect[max(y - w, 0)]++;
    yvect[min(y + w, H + 1)]--;
  }
  int sum = 0;
  for (int i = 0; i < W; i++) {
    sum += xvect[i];
    if (sum == 0)
      ans = false;
  }
  sum = 0;
  if (ans == false) {
    ans = true;
    for (int i = 0; i < H; i++) {
      sum += yvect[i];
      if (sum == 0)
        ans = false;
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}


Error: 0

Fixed submission:

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

using namespace std;

int main() {
  int N, W, H, x, y, w;
  cin >> N >> W >> H;
  vector<int> xvect(W + 2, 0), yvect(H + 2, 0);
  bool ans = true;
  for (int i = 0; i < N; i++) {
    cin >> x >> y >> w;
    xvect[max(x - w, 0)]++;
    xvect[min(x + w + 1, W + 1)]--;
    yvect[max(y - w, 0)]++;
    yvect[min(y + w + 1, W + 1)]--;
  }
  int sum = 0;
  for (int i = 0; i <= W; i++) {
    sum += xvect[i];
    if (sum == 0)
      ans = false;
  }
  sum = 0;
  if (ans == false) {
    ans = true;
    for (int i = 0; i <= H; i++) {
      sum += yvect[i];
      if (sum == 0)
        ans = false;
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}
Problem p01712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
#define N 100002
#define p push_back
#define m make_pair
#define b begin()
#define sz size()
#define s second
#define f first
#define e end()
#define rx r[0]
#define ry r[1]
using namespace std;
typedef pair<int, int> P;

int main() {
  int n, w, h, x, y, ra, be, en, flag[2], k[2][N], t[2][N];
  vector<P> r[2];
  cin >> n >> w >> h;
  while (n--) {
    cin >> x >> y >> ra;
    int xmax = x + ra, xmin = x - ra, ymax = y + ra, ymin = y - ra;
    if (xmax > w)
      xmax = w;
    if (xmin < 0)
      xmin = 0;
    if (ymax > h)
      ymax = h;
    if (ymin < 0)
      ymin = 0;
    rx.p(m(xmin, xmax));
    ry.p(m(ymin, ymax));
  }
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++)
      k[i][j] = 0;
    for (int j = 0; j < r[i].size(); j++)
      k[i][r[i][j].f]++, k[i][r[i][j].s]--;
    t[i][0] = k[i][0];
    for (int j = 1; j < N; j++)
      t[i][j] = t[i][j - 1] + k[i][j];
  }
  flag[0] = flag[1] = 1;
  for (int i = 0; i < w; i++)
    if (!t[0][i])
      flag[0] = 0;
  for (int i = 0; i < h; i++)
    if (!t[1][i])
      flag[1] = 0;
  if (flag[0] || flag[1])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#define p push_back
#define m make_pair
#define s second
#define f first
using namespace std;
typedef pair<int, int> P;

int main() {
  int n, w, h, x, y, r, flag;
  vector<P> rx, ry;
  cin >> n >> w >> h;
  while (n--) {
    cin >> x >> y >> r;
    int max_x = x + r, min_x = x - r, max_y = y + r, min_y = y - r;
    if (max_x > w)
      max_x = w;
    if (min_x < 0)
      min_x = 0;
    if (max_y > h)
      max_y = h;
    if (min_y < 0)
      min_y = 0;
    rx.p(m(min_x, max_x));
    ry.p(m(min_y, max_y));
  }
  sort(rx.begin(), rx.end());
  sort(ry.begin(), ry.end());
  for (int i = 0; i < rx.size() - 1; i++) {
    if (rx[i].s >= rx[i + 1].f) {
      int begin = rx[i].f;
      int end = max(rx[i].s, rx[i + 1].s);
      rx[i] = m(begin, end);
      rx.erase(rx.begin() + i + 1);
      i--;
    }
  }
  for (int i = 0; i < ry.size() - 1; i++) {
    if (ry[i].s >= ry[i + 1].f) {
      int begin = ry[i].f;
      int end = max(ry[i].s, ry[i + 1].s);
      ry[i] = m(begin, end);
      ry.erase(ry.begin() + i + 1);
      i--;
    }
  }
  if (rx.size() != 1 || ry.size() != 1)
    cout << "No" << endl;
  else if ((rx[0].f == 0 && rx[0].s == w) || (ry[0].f == 0 && ry[0].s == h))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p01712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int flagx[100001];
int flagy[100001];
int n, w, h, x, y, z;

int main() {
  cin >> n >> w >> h;
  for (int i = 0; i < w; i++)
    flagx[i] = 0;
  for (int i = 0; i < h; i++)
    flagy[i] = 0;

  for (int i = 0; i < n; i++) {
    cin >> x >> y >> z;
    if (x - z >= 0) {
      flagx[x - z]++;
    } else {
      flagx[0]++;
    }
    if (x + z <= w)
      flagx[x + z]--;
    if (y - z >= 0) {
      flagy[y - z]++;
    } else {
      flagy[0]++;
    }
    if (y + z - 1 <= h)
      flagy[y + z]--;
  }
  for (int i = 1; i < w; i++) {
    flagx[i] += flagx[i - 1];
  }
  for (int i = 1; i < h; i++) {
    flagy[i] += flagy[i - 1];
  }

  int a, b;
  for (a = 0; a < w; a++) {
    if (flagx[a] == 0)
      break;
  }
  for (b = 0; b < h; b++) {
    if (flagy[b] == 0)
      break;
  }
  if (a == w || b == h) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int flagx[100001];
int flagy[100001];
int n, w, h, x, y, z;

int main() {
  cin >> n >> w >> h;
  for (int i = 0; i < w; i++)
    flagx[i] = 0;
  for (int i = 0; i < h; i++)
    flagy[i] = 0;

  for (int i = 0; i < n; i++) {
    cin >> x >> y >> z;
    for (int j = 0; j <= z; j++) {
      if (x - j >= 0)
        flagx[x - j] = 1;
      if (x + j - 1 <= w)
        flagx[x + j - 1] = 1;
      if (y - j >= 0)
        flagy[y - j] = 1;
      if (y + j - 1 <= h)
        flagy[y + j - 1] = 1;
    }
  }
  int a, b;
  for (a = 0; a < w; a++) {
    if (flagx[a] == 0)
      break;
  }
  for (b = 0; b < h; b++) {
    if (flagy[b] == 0)
      break;
  }
  if (a == w || b == h) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p01712 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N, W, H, x, y, w, a = 0, b = 0, flag = 0;
  vector<pair<int, int>> X, Y;
  cin >> N >> W >> H;
  for (int k = 0; k < N; k++) {
    cin >> x >> y >> w;
    X.push_back(make_pair(max(0, x - w), min(x + w, W)));
    Y.push_back(make_pair(max(0, y - w), min(y + w, H)));
  }
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  for (int i = 0; i < N; i++) {
    if (a < X[i].first)
      break;
    a = max(a, X[i].second);
    if (i == N - 1 && a == W)
      flag = 1;
  }
  for (int i = 0; i < N; i++) {
    if (b < Y[i].first)
      break;
    b = max(b, Y[i].second);
    if (i == N - 1 && b == H)
      flag = 1;
  }
  if (flag == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int N, W, H, x, y, w, X[100002] = {}, Y[100002] = {}, flag = 0;

  cin >> N >> W >> H;
  for (int k = 0; k < N; k++) {
    cin >> x >> y >> w;
    for (int i = x - w; i < x + w && i < W; i++) {
      if (i < 0)
        i = 0;
      X[i] = H - 1;
    }
    for (int i = y - w; i < y + w && i < H; i++) {
      if (i < 0)
        i = 0;
      Y[i] = W - 1;
    }
  }
  for (int i = 0; i < W; i++) {
    if (X[i] != H - 1)
      break;
    if (i == W - 1)
      flag++;
  }
  for (int i = 0; i < H; i++) {
    if (Y[i] != W - 1)
      break;
    if (i == H - 1)
      flag++;
  }
  if (flag > 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p01712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

#define REP(i, n) for (int i = 0; i < n; i++)
#define DEBUG 1

using namespace std;

int minusToZero(int a) {
  if (a <= 0) {
    return 0;
  } else
    return a;
}

int overNumToLimit(int a, int limit) {
  if (a >= limit) {
    return limit;
  } else {
    return a;
  }
}

int main() {

  int n, w, h;
  cin >> n >> w >> h;

  int *flagX;
  int *flagY;
  flagX = new int[2 * w + 1];
  flagY = new int[2 * h + 1];

  REP(i, 2 * w + 1) { flagX[i] = 0; }
  REP(i, 2 * h + 1) { flagY[i] = 0; }

  REP(i, n) {
    int tmpX, tmpY, tmpW;
    cin >> tmpX >> tmpY >> tmpW;

    flagX[minusToZero(2 * (tmpX - tmpW))]++;
    flagX[overNumToLimit(2 * (tmpX + tmpW) + 1, 2 * w)]--;

    flagY[minusToZero(2 * (tmpY - tmpW))]++;
    flagY[overNumToLimit(2 * (tmpY + tmpW) + 1, 2 * h)]--;
  }

  int ansFlag = 0;
  for (int i = 1; i < 2 * w + 1; i++) {
    flagX[i] += flagX[i - 1];
  }
  for (int i = 1; i < 2 * h + 1; i++) {
    flagY[i] += flagY[i - 1];
  }
  REP(i, 2 * w) {
    if (flagX[i] <= 0) {
      ansFlag++;
      break;
    }
  }
  REP(i, 2 * h) {
    if (flagY[i] <= 0) {
      ansFlag++;
      break;
    }
  }
  if (ansFlag == 2) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>

#define DEBUG 0

using namespace std;

int min(int a, int b) { return a < b ? a : b; }

int main() {

  int n, w, h;
  int *flagW;
  int *flagH;
  cin >> n >> w >> h;

  flagW = new int[w + 1];
  for (int i = 0; i <= w; i++) {
    flagW[i] = 0;
  }
  flagH = new int[h + 1];
  for (int i = 0; i <= h; i++) {
    flagH[i] = 0;
  }
  int touchCntX = 0;
  int touchCntY = 0;

  for (int i = 0; i < n; i++) {
    int tmpX, tmpY, tmpW;
    cin >> tmpX >> tmpY >> tmpW;

    int touchFirstX = 0;
    int touchFirstY = 0;
    for (int j = tmpX - tmpW; j <= tmpX + tmpW; j++) {
      if (j < 0 || w < j) {
        continue;
      }
      if (flagW[j] == 0) {
        touchFirstX = 0;
      }
      if (flagW[j] >= 1 && touchFirstX == 0) {
        touchFirstX = 1;
        touchCntX++;
      }
      flagW[j] = 1;
    }
    for (int j = tmpY - tmpW; j <= tmpY + tmpW; j++) {
      if (j < 0 || h < j) {
        continue;
      }
      if (flagH[j] == 0) {
        touchFirstY = 0;
      }
      if (flagH[j] >= 1 && touchFirstY == 0) {
        touchFirstY = 1;
        touchCntY++;
      }
      flagH[j] = 1;
    }
  }
  int ansFlag = 0;
  for (int i = 0; i <= w; i++) {
    if (DEBUG)
      cout << flagW[i] << " ";
    if (flagW[i] == 0 || touchCntX != n - 1) {
      ansFlag++;
      break;
    }
  }
  if (DEBUG)
    cout << endl;
  for (int i = 0; i <= h; i++) {
    if (DEBUG)
      cout << flagH[i] << " ";
    if (flagH[i] == 0 || touchCntY != n - 1) {
      ansFlag++;
      break;
    }
  }
  if (DEBUG)
    cout << endl;
  if (ansFlag == 2) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}
Problem p01712 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define loop(n, i) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

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

  vector<int> W(w + 1), H(h + 1);
  loop(n, i) {
    int x, y, p;
    cin >> x >> y >> p;
    W[max(x - p, 0)] += 1;
    W[min(x + p, w)] += -1;
    H[max(y - p, 0)] += 1;
    H[min(y + p, h)] += -1;
  }
  loop(w, i) W[i + 1] += W[i];
  loop(h, i) H[i + 1] += H[i];
  int ok = 1;
  loop(w, i) ok = ok && W[i];
  if (!ok) {
    ok = 1;
    loop(h, i) ok = ok && H[i];
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}

Error: -6
malloc(): corrupted top size


Fixed submission:

#include <bits/stdc++.h>

#define loop(n, i) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

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

  vector<int> W(w + 1), H(h + 1);
  loop(n, i) {
    int x, y, p;
    cin >> x >> y >> p;
    W[max(x - p, 0)] = 1;
    W[min(x + p, w + 1)] = -1;
    H[max(y - p, 0)] = 1;
    H[min(y + p, h + 1)] = -1;
  }
  loop(w, i) W[i + 1] += W[i];
  loop(h, i) H[i + 1] += H[i];
  int ok = 1;
  loop(w - 1, i) ok = ok && W[i];
  if (!ok) {
    ok = 1;
    loop(h - 1, i) ok = ok && H[i];
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}
Problem p01712 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define for_(i, a, b) for (int i = a; i < b; ++i)

typedef pair<int, int> pii;
int N, W, H;

int main() {
  cin >> N >> W >> H;
  vector<pii> xp, yp;

  for_(i, 0, N) {
    int x, y, w;
    cin >> x >> y >> w;
    xp.push_back(pii(max(x - w, 0), min(x + w, W)));
    yp.push_back(pii(max(y - w, 0), min(y + w, H)));
  }

  sort(xp.begin(), xp.end());
  sort(yp.begin(), yp.end());

  int xe = 0, ye = 0;
  for_(i, 0, N) {
    if (xe >= xp[i].first)
      xe = max(xe, xp[i].second);
    if (ye >= yp[i].first)
      ye = max(ye, yp[i].second);
  }

  bool fx = (xe == W), fy = (ye == H);
  cout << (fx || fy ? "Yes" : "No") << endl;
}

Error: TLE

Fixed submission:

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

#define for_(i, a, b) for (int i = a; i < b; ++i)

int N, W, H;

int main() {
  cin >> N >> W >> H;
  vector<bool> X(W + 1, 0), Y(H + 1, 0);

  for_(i, 0, N) {
    int x, y, w;
    cin >> x >> y >> w;
    for_(j, x - w + 1, x + w + 1) if (0 < j && j <= W) X[j] = 1;
    for_(j, y - w + 1, y + w + 1) if (0 < j && j <= H) Y[j] = 1;
  }

  bool fx = 1, fy = 1;
  for_(i, 1, W + 1) if (!X[i]) fx = 0;
  for_(i, 1, H + 1) if (!Y[i]) fy = 0;
  cout << (fx || fy ? "Yes" : "No") << endl;
}
Problem p01712 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, w, h;
  cin >> n >> w >> h;
  pair<int, int> temp(0, 0);
  vector<pair<int, int>> line(n, temp), column(n, temp);
  vector<pair<int, int>>::iterator it;
  for (int i = 0; i < n; i++) {
    int x, y, r;
    cin >> x >> y >> r;
    int xs = x - r, xg = x + r, ys = y - r, yg = y + r;
    column[i].first = xs;
    column[i].second = xg;
    line[i].first = ys;
    line[i].second = yg;
  }

  sort(column.begin(), column.end());
  sort(line.begin(), line.end());

  bool flagx = true, flagy = true;
  int x = 0, y = 0;
  for (int i = 0; i < n; i++) {
    int xs, xg;
    xs = column[i].first;
    xg = column[i].second;
    if (xs > x) {
      flagx = false;
      if (!flagy) {
        break;
      }
    } else {
      if (xg > x) {
        x = xg;
      }
    }
    int ys, yg;
    ys = line[i].first;
    yg = line[i].second;
    if (ys > y) {
      flagy = false;
      if (!flagx) {
        break;
      }
    } else {
      if (yg > y) {
        y = yg;
      }
    }
  }
  if (x < w) {
    flagx = false;
  }
  if (y < h) {
    flagy = false;
  }

  if (flagx || flagy)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Error: TLE

Fixed submission:


#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, w, h;
  cin >> n >> w >> h;
  vector<bool> line(h, false), column(w, false);

  for (int i = 0; i < n; i++) {
    int x, y, r;
    cin >> x >> y >> r;
    for (int j = -r; j < r; j++) {
      if (x + j >= 0 && x + j < w) {
        column[x + j] = true;
      }
      if (y + j >= 0 && y + j < h) {
        line[y + j] = true;
      }
    }
  }
  bool flag1 = true, flag2 = true;
  for (int i = 0; i < h; i++) {
    if (!line[i]) {
      flag1 = false;
      break;
    }
  }
  for (int i = 0; i < w; i++) {
    if (!column[i]) {
      flag2 = false;
      break;
    }
  }
  if (flag1 || flag2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}