Problem p03240 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}

struct P {
  int x, y, h;
};

void solve() {
  int N;
  cin >> N;

  vector<P> C;

  for (int i = 0; i < N; i++) {
    int x, y, h;
    cin >> x >> y >> h;
    C.push_back({x, y, h});
  }

  for (int x = 0; x <= 100; x++) {
    for (int y = 0; y <= 100; y++) {
      int h = 0;
      for (int i = 0; i < N; i++) {
        if (C[i].h != 0 && C[i].h + abs(C[i].x - x) + abs(C[i].y - y) != 0) {
          h = C[i].h + abs(C[i].x - x) + abs(C[i].y - y);
          break;
        }
      }
      if (h == 0) {
        assert(false);
      }
      bool ok = true;
      for (int i = 0; i < N; i++) {
        if (h - abs(C[i].x - x) - abs(C[i].y - y) != C[i].h)
          ok = false;
      }
      if (ok) {
        cout << x << " " << y << " " << h << endl;
        return;
      }
    }
  }
  assert(false);
}

int main() {
#ifdef LOCAL_ENV
  cin.exceptions(ios::failbit);
#endif
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);

  solve();
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}

struct P {
  int x, y, h;
};

void solve() {
  int N;
  cin >> N;

  vector<P> C;

  for (int i = 0; i < N; i++) {
    int x, y, h;
    cin >> x >> y >> h;
    C.push_back({x, y, h});
  }

  for (int x = 0; x <= 100; x++) {
    for (int y = 0; y <= 100; y++) {
      int h = 0;
      for (int i = 0; i < N; i++) {
        if (C[i].h != 0 && C[i].h + abs(C[i].x - x) + abs(C[i].y - y) != 0) {
          h = C[i].h + abs(C[i].x - x) + abs(C[i].y - y);
          break;
        }
      }
      if (h == 0) {
        assert(false);
      }
      bool ok = true;
      for (int i = 0; i < N; i++) {
        if (max(0, h - abs(C[i].x - x) - abs(C[i].y - y)) != C[i].h)
          ok = false;
      }
      if (ok) {
        cout << x << " " << y << " " << h << endl;
        return;
      }
    }
  }
  assert(false);
}

int main() {
#ifdef LOCAL_ENV
  cin.exceptions(ios::failbit);
#endif
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);

  solve();
}