Problem p03774 (C++)

Buggy submission (status: Runtime Error):
// _______  _____  _______  _____  _______ _______ _____ _______ _____ _    _
// _______ |       |     | |  |  | |_____] |______    |      |      |      |
// \  /  |______
// |_____  |_____| |  |  | |       |______    |    __|__    |    __|__   \/
// |______
//
//  _____   ______  _____   ______  ______ _______ _______ _______ _____ __   _
//  ______   /
// |_____] |_____/ |     | |  ____ |_____/ |_____| |  |  | |  |  |   |   | \  |
// |  ____  / |       |    \_ |_____| |_____| |    \_ |     | |  |  | |  |  |
// __|__ |  \_| |_____| .
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define FOR(I, A, B) for (int I = int(A); I < int(B); ++I)
#define FORR(I, A, B) for (int I = int((B)-1); I >= int(A); --I)
#define POSL(x, v)                                                             \
  (lower_bound(x.begin(), x.end(), v) - x.begin()) // ai>=v  x is sorted
#define POSU(x, v)                                                             \
  (upper_bound(x.begin(), x.end(), v) - x.begin()) // ai>v  x is sorted
ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll c = gcd(a, b);
  return ((a / c) * (b / c) * c);
} // saisyo kobaisu z
const ll INF = 1e18 + 7;
const ll MOD = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, M;
  cin >> N >> M;
  vector<ll> a(N), b(N), c(N), d(N);
  FOR(i, 0, N) { cin >> a[i] >> b[i]; }
  FOR(j, 0, M) { cin >> c[j] >> d[j]; }
  FOR(i, 0, N) {
    ll ma = 10000000000;
    ll ans = 0;
    FOR(j, 0, M) {
      if (abs(a[i] - c[j]) + abs(b[i] - d[j]) < ma) {
        ma = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }
}

Fixed submission:
// _______  _____  _______  _____  _______ _______ _____ _______ _____ _    _
// _______ |       |     | |  |  | |_____] |______    |      |      |      |
// \  /  |______
// |_____  |_____| |  |  | |       |______    |    __|__    |    __|__   \/
// |______
//
//  _____   ______  _____   ______  ______ _______ _______ _______ _____ __   _
//  ______   /
// |_____] |_____/ |     | |  ____ |_____/ |_____| |  |  | |  |  |   |   | \  |
// |  ____  / |       |    \_ |_____| |_____| |    \_ |     | |  |  | |  |  |
// __|__ |  \_| |_____| .
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define FOR(I, A, B) for (int I = int(A); I < int(B); ++I)
#define FORR(I, A, B) for (int I = int((B)-1); I >= int(A); --I)
#define POSL(x, v)                                                             \
  (lower_bound(x.begin(), x.end(), v) - x.begin()) // ai>=v  x is sorted
#define POSU(x, v)                                                             \
  (upper_bound(x.begin(), x.end(), v) - x.begin()) // ai>v  x is sorted
ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll c = gcd(a, b);
  return ((a / c) * (b / c) * c);
} // saisyo kobaisu z
const ll INF = 1e18 + 7;
const ll MOD = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, M;
  cin >> N >> M;
  vector<ll> a(N), b(N), c(M), d(M);
  FOR(i, 0, N) { cin >> a[i] >> b[i]; }
  FOR(j, 0, M) { cin >> c[j] >> d[j]; }
  FOR(i, 0, N) {
    ll ma = 10000000000;
    ll ans = 0;
    FOR(j, 0, M) {
      if (abs(a[i] - c[j]) + abs(b[i] - d[j]) < ma) {
        ma = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }
}