Problem p03240 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep(i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#define debug(x) cout << #x " => " << (x) << endl
#ifdef LOCAL
#include "../../Lib/cout_container.hpp"
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace {
struct INIT {
  INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} INIT;
} // namespace

int main(void) {
  int n;
  cin >> n;
  struct XYH {
    lint x, y, h;
  };
  vector<XYH> xyh(n);
  rep(i, n) cin >> xyh[i].x >> xyh[i].y >> xyh[i].h;
  auto comp = [](XYH &a, XYH &b) { return a.h != 0; };
  sort(all(xyh), comp);
  rep(CX, 101) {
    rep(CY, 101) {
      lint H = xyh[0].h != 0
                   ? xyh[0].h + abs(xyh[0].x - CX) + abs(xyh[0].y - CY)
                   : 1;
      bool ok = true;
      rep(i, 1, n) {
        lint Htmp = xyh[i].h + abs(xyh[i].x - CX) + abs(xyh[i].y - CY);
        if (xyh[i].h != 0) {
          if (H != Htmp) {
            ok = false;
            break;
          }
        } else {
          if (H > Htmp) {
            ok = false;
            break;
          }
        }
      }
      if (ok) {
        cout << CX << " " << CY << " " << H << endl;
        return 0;
      }
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep(i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#define debug(x) cout << #x " => " << (x) << endl
#ifdef LOCAL
#include "../../Lib/cout_container.hpp"
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace {
struct INIT {
  INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} INIT;
} // namespace

int main(void) {
  int n;
  cin >> n;
  struct XYH {
    lint x, y, h;
  };
  vector<XYH> xyh(n);
  rep(i, n) cin >> xyh[i].x >> xyh[i].y >> xyh[i].h;
  sort(all(xyh), [](XYH &a, XYH &b) { return a.h > b.h; });
  rep(CX, 101) {
    rep(CY, 101) {
      lint H = xyh[0].h != 0
                   ? xyh[0].h + abs(xyh[0].x - CX) + abs(xyh[0].y - CY)
                   : 1;
      bool ok = true;
      rep(i, 1, n) {
        lint Htmp = xyh[i].h + abs(xyh[i].x - CX) + abs(xyh[i].y - CY);
        if (xyh[i].h != 0) {
          if (H != Htmp) {
            ok = false;
            break;
          }
        } else {
          if (H > Htmp) {
            ok = false;
            break;
          }
        }
      }
      if (ok) {
        cout << CX << " " << CY << " " << H << endl;
        return 0;
      }
    }
  }
  return 0;
}