Problem p03241 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9 + 7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout << (v) << endl
#define CIN(n)                                                                 \
  int(n);                                                                      \
  cin >> (n)
#define LCIN(n)                                                                \
  LL(n);                                                                       \
  cin >> (n)
#define SCIN(n)                                                                \
  string(n);                                                                   \
  cin >> (n)
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

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

#define FOREACH(x, a) for (auto &(x) : (a))

#define ALL(obj) (obj).begin(), (obj).end()

#define P pair<LL, LL>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)), a.erase(unique(ALL(a)), a.end())
#define ENDL cout << endl

typedef string::const_iterator State;
class PalseError {};
class Edge {
public:
  int from, to, value;
  Edge(LL a, LL b, LL c) {
    from = a;
    to = b;
    value = c;
  }
  Edge(LL a, LL b) {
    from = a;
    to = b;
  }
};
int main() {
  CIN(N);

  vector<vector<set<long>>> vec(101, vector<set<long>>(101));
  for (int a = 0; a <= 100; a++) {
    for (int b = 0; b <= 100; b++) {
      vec.at(a).at(b).clear();
    }
  }
  REP(i, N) {
    CIN(x);
    CIN(y);
    long h;
    cin >> h;
    if (h == 0L) {
      vec.at(x).at(y).insert(-1);
      continue;
    }
    for (int a = 0; a <= 100; a++) {
      for (int b = 0; b <= 100; b++) {
        long ans = h + abs(x - a) + abs(y - b);
        vec.at(a).at(b).insert(ans);
      }
    }
  }
  int ans = 0;
  for (int x = 0; x <= 100; x++) {
    for (int y = 0; y <= 100; y++) {
      if (vec.at(x).at(y).size() == 1) {
        long h;
        for (long i : vec.at(x).at(y)) {
          h = i;
        }
        if (h <= 0)
          continue;
        ans++;
        //       cout<<x<<" "<<y<<" "<<h<<endl;
        if (ans >= 2) {
          return 1;
        }
      }
    }
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9 + 7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout << (v) << endl
#define CIN(n)                                                                 \
  int(n);                                                                      \
  cin >> (n)
#define LCIN(n)                                                                \
  LL(n);                                                                       \
  cin >> (n)
#define SCIN(n)                                                                \
  string(n);                                                                   \
  cin >> (n)
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

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

#define FOREACH(x, a) for (auto &(x) : (a))

#define ALL(obj) (obj).begin(), (obj).end()

#define P pair<LL, LL>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)), a.erase(unique(ALL(a)), a.end())
#define ENDL cout << endl

typedef string::const_iterator State;
class PalseError {};
class Edge {
public:
  int from, to, value;
  Edge(LL a, LL b, LL c) {
    from = a;
    to = b;
    value = c;
  }
  Edge(LL a, LL b) {
    from = a;
    to = b;
  }
};
int main() {
  CIN(N);
  CIN(M);
  for (int a = M / N; a >= 0; a--) {
    if (M % a == 0) {
      COUT(a);
      return 0;
    }
  }
  return 0;
}