Problem p01712 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define INF 1e09

using std::cin;
using std::cout;
using std::endl;
using std::fixed;
using std::list;
using std::make_pair;
using std::map;
using std::max;
using std::min;
using std::pair;
using std::priority_queue;
using std::queue;
using std::set; // insert erase find count
using std::setprecision;
using std::stack;
using std::string;
using std::vector;

typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, pair<int, int>> PIII;

int main(void) {
  int n;
  int w;
  int h;
  cin >> n >> w >> h;
  VI ew(w + 1, 0);
  VI sn(h + 1, 0);
  for (int i = 0; i < n; i++) {
    int x;
    int y;
    int iw;
    cin >> x >> y >> iw;
    int x_start = x - iw;
    if (x_start < 0) {
      x_start = 0;
    }
    int x_end = x + iw;
    if (x_end > w) {
      x_end = w;
    }
    int y_start = y - iw;
    if (y_start < 0) {
      y_start = 0;
    }
    int y_end = y + iw;
    if (y_end > h) {
      y_end = h;
    }
    /*
    for (int i = x_start; i <= x_end; i++) {
        ew[i]++;
    }
    for (int i = y_start; i <= y_end; i++) {
        sn[i]++;
    }
    */
    ew[x_start]++;
    ew[x_end]--;
    sn[y_start]++;
    sn[y_end]--;
    /*
       for (int i = 0; i < w; i++) {
       cout << ew[i] << " ";
       }
       cout << endl;
       for (int i = 0; i < h; i++) {
       cout << sn[i] << " ";
       }
       cout << endl;
    */
  }

  for (int i = 1; i < w; i++) {
    ew[i] += ew[i - 1];
  }
  for (int i = 1; i < h; i++) {
    sn[i] += sn[i - 1];
  }

  bool xcheck = true;
  bool ycheck = true;
  for (int i = 0; i < w; i++) {
    if (ew[i] == 0) {
      xcheck = false;
    }
  }
  for (int i = 0; i < h; i++) {
    if (sn[i] == 0) {
      ycheck = false;
    }
  }
  if (xcheck == true || ycheck == true) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

#define INF 1e09

using std::cin;
using std::cout;
using std::endl;
using std::fixed;
using std::list;
using std::make_pair;
using std::map;
using std::max;
using std::min;
using std::pair;
using std::priority_queue;
using std::queue;
using std::set; // insert erase find count
using std::setprecision;
using std::stack;
using std::string;
using std::vector;

typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, pair<int, int>> PIII;

int main(void) {
  int n;
  int w;
  int h;
  cin >> n >> w >> h;
  VI ew(w, 0);
  VI sn(h, 0);
  for (int i = 0; i < n; i++) {
    int x;
    int y;
    int iw;
    cin >> x >> y >> iw;
    int x_start = x - iw;
    if (x_start < 0) {
      x_start = 0;
    }
    int x_end = x + iw - 1;
    if (x_end >= w) {
      x_end = w - 1;
    }
    int y_start = y - iw;
    if (y_start < 0) {
      y_start = 0;
    }
    int y_end = y + iw - 1;
    if (y_end >= h) {
      y_end = h - 1;
    }
    for (int i = x_start; i <= x_end; i++) {
      ew[i]++;
    }
    for (int i = y_start; i <= y_end; i++) {
      sn[i]++;
    }
    /*
       for (int i = 0; i < w; i++) {
       cout << ew[i] << " ";
       }
       cout << endl;
       for (int i = 0; i < h; i++) {
       cout << sn[i] << " ";
       }
       cout << endl;
     */
  }

  bool xcheck = true;
  bool ycheck = true;
  for (int i = 0; i < w; i++) {
    if (ew[i] == 0) {
      xcheck = false;
    }
  }
  for (int i = 0; i < h; i++) {
    if (sn[i] == 0) {
      ycheck = false;
    }
  }
  if (xcheck == true || ycheck == true) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}